Showing posts with label py2exe python. Show all posts
Showing posts with label py2exe python. Show all posts

Tuesday, March 31, 2009

py2exe can't import packages that should be available (simplejson)

In my py2exe build script, I was specifying a few modules to be imported that for some reason would fail to import. I could import these from the python prompt, but the build script would give the following:

running py2exe
*** searching for required modules ***
Traceback (most recent call last):
File "setup.py", line 235, in
console=[ 'runcm.py' ],
File "C:\PYTHON25\LIB\distutils\core.py", line 151, in setup
dist.run_commands()
File "C:\PYTHON25\LIB\distutils\dist.py", line 974, in run_commands
self.run_command(cmd)
File "C:\PYTHON25\LIB\distutils\dist.py", line 994, in run_command
cmd_obj.run()
File "C:\Python25\lib\site-packages\py2exe\build_exe.py", line 243, in run
self._run()
File "C:\Python25\lib\site-packages\py2exe\build_exe.py", line 296, in _run
self.find_needed_modules(mf, required_files, required_modules)
File "C:\Python25\lib\site-packages\py2exe\build_exe.py", line 1297, in find_n
eeded_modules
mf.import_hook(mod)
File "C:\Python25\lib\site-packages\py2exe\mf.py", line 719, in import_hook
return Base.import_hook(self,name,caller,fromlist,level)
File "C:\Python25\lib\site-packages\py2exe\mf.py", line 136, in import_hook
q, tail = self.find_head_package(parent, name)
File "C:\Python25\lib\site-packages\py2exe\mf.py", line 204, in find_head_pack
age
raise ImportError, "No module named " + qname
ImportError: No module named simplejson


Apparently the problem has to do with that the modules in site-packages stored as zipped eggs would not import. Simply unzipping the simplejson egg contents so that the simplejson directory was in the site-packages directory solved the problem.