我正在尝试使用cx_freeze从导入了pyrax(以与Rackspace交互)的Python脚本中创建Windows可执行文件。 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'
我在Windows 8上通过Continuum Anaconda安装运行python 2.7。我已经使用pip安装了oslo v1.0.0(并尝试将其重新安装,但无济于事)。 Cx_freeze是版本4.3.3,而oslo模块不是egg或zip,而是与其他所有文件夹一起放在site-packages下。
“导入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]
)
思想和变通办法,不胜感激。谢谢!
最佳答案
重新发布作为答案:
添加到build_exe选项:
"namespace_packages":["oslo"]
oslo
是一个名称空间包,cx_Freeze需要了解它才能正常工作。显然,您还需要将其添加到软件包中:
"packages":["oslo"]
我不确定为什么也需要执行此步骤。
关于python - cx_freeze找不到oslo模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26821102/