I'm trying to use cx_freeze to create a Windows executable from a Python script that imports pyrax (to interface with Rackspace). Pyrax requires oslo (https://github.com/openstack/oslo.utils), a module for working with OpenStack that I have installed. When I try to run the compiled .exe, it says that it can't find the module 'oslo.utils'. When I try to include that module, or just the oslo module, in my setup.py file, I get the following error:
running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 45, in <module>
executables = [execu]
File "C:\Users\Devin\Anaconda\lib\site-packages\cx_Freeze\dist.py", line 362, in setup
distutils.core.setup(**attrs)
File "C:\Users\Devin\Anaconda\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "C:\Users\Devin\Anaconda\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "C:\Users\Devin\Anaconda\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Users\Devin\Anaconda\lib\distutils\command\build.py", line 127, in run
self.run_command(cmd_name)
File "C:\Users\Devin\Anaconda\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "C:\Users\Devin\Anaconda\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Users\Devin\Anaconda\lib\site-packages\cx_Freeze\dist.py", line 232, in run
freezer.Freeze()
File "C:\Users\Devin\Anaconda\lib\site-packages\cx_Freeze\freezer.py", line 606, in Freeze
self.finder = self._GetModuleFinder()
File "C:\Users\Devin\Anaconda\lib\site-packages\cx_Freeze\freezer.py", line 346, in _GetModuleFinder
finder.IncludeModule(name)
File "C:\Users\Devin\Anaconda\lib\site-packages\cx_Freeze\finder.py", line 678, in IncludeModule
namespace = namespace)
File "C:\Users\Devin\Anaconda\lib\site-packages\cx_Freeze\finder.py", line 386, in _ImportModule
raise ImportError("No module named %r" % name)
ImportError: No module named 'oslo.utils'
I'm on Windows 8 running Python 2.7 via a Continuum Anaconda install. I've installed oslo v1.0.0 using pip (and reinstalled it in an attempt to fix this, but to no avail). Cx_freeze is version 4.3.3, and the oslo module not an egg or zip, but is foldered with everything else under site-packages.
'Import oslo' and 'import oslo.utils' both work in the interpreter. Other modules manually included in setup.py work correctly. My setup.py file looks like this:
import sys
from cx_Freeze import setup, Executable
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
# include email.__init__ lazy imports manually for pyrax
MIMENAMES = [
'audio',
'base',
'image',
'message',
'multipart',
'nonmultipart',
'text',
]
email_includes = ['email.mime.' + x for x in MIMENAMES]
includes = ['oslo.utils']
includes.extend(email_includes)
include_files = []
execu = Executable(
script = "main.py",
initScript = None,
base = base,
targetName = "main.exe",
compress = False,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup( name = "issgmain",
version = "0.1",
description = "my description",
options = {"build_exe": {"includes":includes, "include_files": include_files}},
executables = [execu]
)
Thoughts and workarounds much appreciated. Thanks!
Reposting as an answer:
Add to the build_exe options:
"namespace_packages":["oslo"]
oslo
is a namespace package, and cx_Freeze needs to know about it for things to work correctly.
Apparently you also need to add it to packages:
"packages":["oslo"]
I'm not sure why this step is needed as well.