python - py2exe fails with "No module named 'clr'" when trying to build exe from script using pythonnet -


i created python script uses pythonnet. script in file named main.py. when run script command line (simply typing main.py @ windows command prompt), imported pythonnet module clr works fine. when try build exe error saying: no module named clr.

to isolate cause of this, have verified building executable (in case simple tkinter app) using py2exe works. have python 3.4 installed , have verified where python points c:\python34\python.exe.

the error occurs @ executable build time , seems triggered including clr in section {"includes":["sip","clr"]}} in setup.py py2exe. full traceback below:

traceback (most recent call last):   file "setup.py", line 32, in <module>     windows = [{'script': "main.py"}],   file "c:\python34\lib\distutils\core.py", line 148, in setup     dist.run_commands()   file "c:\python34\lib\distutils\dist.py", line 917, in run_commands     self.run_command(cmd)   file "c:\python34\lib\distutils\dist.py", line 936, in run_command     cmd_obj.run()   file "c:\python34\lib\site-packages\py2exe\distutils_buildexe.py", line 188, n run     self._run()   file "c:\python34\lib\site-packages\py2exe\distutils_buildexe.py", line 267, n _run     builder.analyze()   file "c:\python34\lib\site-packages\py2exe\runtime.py", line 164, in analyze     mf.import_hook(modname)   file "c:\python34\lib\site-packages\py2exe\mf3.py", line 120, in import_hook     module = self._gcd_import(name)   file "c:\python34\lib\site-packages\py2exe\mf3.py", line 273, in _gcd_import     raise importerror('no module named {!r}'.format(name), name=name) importerror: no module named 'clr' 

i read/tried these:

https://docs.python.org/2/distutils/setupscript.html https://pythonhosted.org/setuptools/setuptools.html http://sourceforge.net/p/py2exe/mailman/message/6937658 

leading me move clr.pyd , python.runtime.dll various locations including location of main.py, c:\python34\lib\site-packages (where originally) , c:\python34\lib\site-packages\py2exe

none of these have worked , don't know try next. can see reason py2exe can't find either clr.pyd or python.runtime.dll or both, can't see why. have ideas?


code details

my main.py script looks this:

import clr clr.addreference("name.xxxx") name.xxxx import aaa clr import system  # functioning code, i've verified works when run command line 

this setup.py file contains (i've left bits commented can see i've tried):

from distutils.core import setup import py2exe, sys, os  mydata_files = [] files in os.listdir('c:\\d\\project\\tools\\data_acquisition\\trunk\\dll'):     f1 = 'c:\\d\\project\\tools\\data_acquisition\\trunk\\dll\\' + files     if os.path.isfile(f1): # skip directories         f2 = '.', [f1]         mydata_files.append(f2)  setup(   data_files=mydata_files,    # options = {"py2exe" : {"includes" : "module1,module2,module3"}}   options = {"py2exe": {"includes":["sip", "clr"]}},   # options = {'py2exe': {'bundle_files': 1 , 'compressed': true,"includes":["sip"]}},   #python setup.py py2exe   #clr.dll , pythonruntime.dll    # options = {'py2exe': {'bundle_files': 1, "skip_archive":1 ,"includes":["sip"]}},   windows = [{'script': "main.py"}],   # data_files=mydata_files,   # zipfile = none ) 

if change line options = {"py2exe": {"includes":["sip", "clr"]}}, options = {"py2exe": {"includes":["sip"]}}, .exe builds, not function correctly.

install description

for reference, performed standard install of py2exe using pip install py2exe. puts py2exe lib\site-packages python install. next, installed pythonnet downloading .whl christoph gohlke's unofficial windows binaries page, using pip install path\to\pythonnet-2.0.0<version_numbers>.whl. puts clr.pyd , python.runtime.dll lib\site-packages python install. this question , answers have further info.

problem

this rather strange behaviour of py2exe hard debug. think purely bug in tool. in addition, error message not helpful.

the problem module clr excluded tool, via hooks.py file. not clear why. can see line exclusion here.

solution

the workaround delete word clr windows_excludes variable hooks.py file in py2exe installation. assuming in standard place - means deleting line 23 in file hooks.py located in c:\python34\lib\site-packages\py2exe. need make sure python.runtime.dll somehow packaged .exe - tested adding data files. here example tested , worked - used simple main.py illustrate import , assure myself program working. left setup.py close possible version, commenting out lines did not suit system

to make .exe - use following (you may not need path python.exe if python aliased python 3 install)

c:\python34\python.exe setup.py py2exe 

main.py

import clr # import clr, don't use not # expertise.  fact imports without error means # i'm pretty sure work  open('out.txt','a') f:     in range(30):         f.write(str(i)) 

setup.py

from distutils.core import setup import py2exe, sys, os  mydata_files = []  # had comment these out did not apply test environment # files in os.listdir('c:\\d\\project\\tools\\data_acquisition\\trunk\\dll'): # f1 = 'c:\\d\\project\\tools\\data_acquisition\\trunk\\dll' + files # if os.path.isfile(f1): # skip directories     # f2 = 'dll', [f1]     # mydata_files.append(f2)  # it's essential python.runtime.dll packaged main.exe # how i've done mydata_files.append(('.',['c:\\python34\\lib\\site-packages\\python.runtime.dll']))  setup(  data_files=mydata_files,  # i've left commented lines in - weren't necessary test # options = {"py2exe" : {"includes" : "module1,module2,module3"}}  # haven't included sip don't have installed, think work options = {"py2exe": {"includes":["clr"]}}, # options = {'py2exe': {'bundle_files': 1 , 'compressed': true,"includes":["sip"]}}, #python setup.py py2exe #clr.dll , pythonruntime.dll  # options = {'py2exe': {'bundle_files': 1, "skip_archive":1 ,"includes":["sip"]}}, windows = [{'script': "main.py"}], # data_files=mydata_files, # zipfile = none ) 

edit: interested - described how isolated , found bug in more detail in a chat conversation.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -