2

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!

10
  • That traceback indicates that something in your setup.py is adding 'oslo.py' to the includes list. The line numbers also indicate that there's more in your setup.py script than you've shown. Includes is a list of module names, not filenames, so you should include 'oslo', without the .py extension.
    – Thomas K
    Nov 8, 2014 at 20:25
  • 1
    OK. Can you do import oslo.utils; print(oslo.utils) to see where it's loaded from in Python?
    – Thomas K
    Nov 9, 2014 at 23:00
  • 1
    OK, and if you put a print(sys.path) into your setup.py file, is C:\Users\Devin\Anaconda\lib\site-packages one of the directories it shows in the list?
    – Thomas K
    Nov 10, 2014 at 18:29
  • 1
    If you add "packages":["oslo"] to the build_exe options, does it make any difference? Can you show the full output from freezing (put it in a pastebin)?
    – Thomas K
    Nov 11, 2014 at 17:13
  • 1
    Ah, wait a minute, oslo is a namespace package. Try with "namespace_packages":["oslo"]
    – Thomas K
    Nov 11, 2014 at 19:11

1 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.