2

我正在尝试使用 cx_freeze 从导入 pyrax 的 Python 脚本创建一个 Windows 可执行文件(以与 Rackspace 交互)。Pyrax 需要 oslo ( https://github.com/openstack/oslo.utils ),这是我安装的用于使用 OpenStack 的模块。当我尝试运行已编译的 .exe 时,它​​说找不到模块“oslo.utils”。当我尝试在 setup.py 文件中包含该模块或仅包含 oslo 模块时,出现以下错误:

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'

我在通过 Continuum Anaconda 安装运行 Python 2.7 的 Windows 8 上。我已经使用 pip 安装了 oslo v1.0.0(并重新安装它试图解决这个问题,但无济于事)。Cx_freeze 是 4.3.3 版,oslo 模块不是 egg 或 zip,而是与 site-packages 下的所有其他内容一起文件夹。

'Import oslo' 和 'import oslo.utils' 都在解释器中工作。setup.py 中手动包含的其他模块可以正常工作。我的 setup.py 文件如下所示:

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]
        )

非常感谢您的想法和解决方法。谢谢!

4

1 回答 1

3

转发作为答案:

添加到 build_exe 选项:

"namespace_packages":["oslo"]

oslo是一个命名空间包,cx_Freeze 需要知道它才能正常工作。

显然你还需要将它添加到包中:

"packages":["oslo"]

我不确定为什么也需要这一步。

于 2014-11-12T18:43:32.517 回答