I have a python script (2.7) with some "interesting" imports at the top. I initially wanted to use py2exe to compile this into an exe that I can more easily distribute (py2exe doesn't find all dependencies).
I have given up and am trying to use cx-freeze instead. But, I am having problem there as well. The problems seem to be libraries I have added to Python (jinja2 and restkit). I see them in my python directory ./Lib/site-packages/Jinja2-2.6-py2.7.egg/jinja2 and here ./Lib/site-packages/restkit-4.2.1-py2.7.egg/restkit.
Here are the imports in my script:
import datetime
from jinja2 import Environment, PackageLoader
from optparse import OptionParser
from datetime import date, timedelta
from restkit import Resource, BasicAuth, request
I am using a setup.py with cx-freeze. Here is the setup.py:
from cx_Freeze import setup, Executable
packages = ["restkit", "jinja2" , "restkit.client" ]
includes = []
includefiles = []
eggsacutibull = Executable(
script = "myScript.py",
initScript = None,
targetName = "myScript.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
name = "myScript",
version = "0.1",
author = 'vickery',
description = "MyScript description",
options = {"build_exe": {"includes":includes, "include_files": includefiles, "packages": packages}},
executables = [eggsacutibull]
)
I run cxfreeze like this:
cxfreeze myScript.py --target-dir exe
I get this in my build:
Missing modules:
? __pypy__ imported from jinja2.debug
? http_parser.http imported from restkit.client
? jinja2._debugsupport imported from jinja2.debug
? jinja2._markupsafe._speedups imported from jinja2._markupsafe
? jinja2.debugrenderer imported from jinja2.debug
? markupsafe imported from jinja2.utils
? pretty imported from jinja2.utils
? socketpool imported from restkit.conn
And, when I try to run the exe, I get this:
Traceback (most recent call last):
File "c:Python27libsite-packages
estkit-4.2.1-py2.7.egg
estkit\__init__.py", line 9, in <module>
from restkit.conn import Connection
File "c:Python27libsite-packages
estkit-4.2.1-py2.7.egg
estkitconn.py", line 14, in <module>
from socketpool import Connector
ImportError: No module named socketpool
Traceback (most recent call last):
File "c:Python27libsite-packagescx_FreezeinitscriptsConsole.py", line 27, in <module>
exec code in m.__dict__
File "myScript.py", line 12, in <module>
ImportError: cannot import name Resource
Edit:
I am now running cxfreeze correctly like this:
python setup.py build
I also added socketpool to my setup.py:
packages = [ "restkit", "jinja2" , "restkit.client", "restkit.conn", "socketpool" ]
But, when I try to build now, I get a build error:
$ python setup.py build
running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 32, in <module>
executables = [eggsacutibull]
File "c:python27libsite-packagescx_Freezedist.py", line 365, in setup
distutils.core.setup(**attrs)
File "c:python27libdistutilscore.py", line 152, in setup
dist.run_commands()
File "c:python27libdistutilsdist.py", line 953, in run_commands
self.run_command(cmd)
File "c:python27libdistutilsdist.py", line 972, in run_command
cmd_obj.run()
File "c:python27libdistutilscommanduild.py", line 127, in run
self.run_command(cmd_name)
File "c:python27libdistutilscmd.py", line 326, in run_command
self.distribution.run_command(command)
File "c:python27libdistutilsdist.py", line 972, in run_command
cmd_obj.run()
File "c:python27libsite-packagescx_Freezedist.py", line 235, in run
freezer.Freeze()
File "c:python27libsite-packagescx_Freezefreezer.py", line 570, in Freeze
self.finder = self._GetModuleFinder()
File "c:python27libsite-packagescx_Freezefreezer.py", line 325, in _GetModuleFinder
finder.IncludePackage(name)
File "c:python27libsite-packagescx_Freezefinder.py", line 534, in IncludePackage
module = self._ImportModule(name, deferredImports)
File "c:python27libsite-packagescx_Freezefinder.py", line 274, in _ImportModule
raise ImportError("No module named %r" % name)
ImportError: No module named 'socketpool'
What has me confused here, is, my script compiles just fine. In addition, I can import these modules from a python shell. For example:
$ python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import socketpool
>>> from restkit import Resource, BasicAuth, request
>>>
How is python resolving modules that is differnt than cxfreeze?
Edit2:
From python I can do this:
>>> import socketpool
>>> print socketpool.__file__
c:python27libsite-packagessocketpool-0.5.2-py2.7.eggsocketpool\__init__.pyc
Is that a non-standard place to look for a package? Can I used PYTHONPATH to coerce cxfreez into looking there for socketpool?
Thanks
See Question&Answers more detail:
os