cmh*_*cmh 5 python distutils virtualenv cx-freeze
当从python3.2项目运行cxfreeze二进制文件时,出现以下运行时错误:
/project/dist/project/distutils/__init__.py:13: UserWarning: The virtualenv distutils package at %s appears to be in the same location as the system distutils?
Traceback (most recent call last):
File "/home/chrish/.virtualenvs/project/lib/python3.2/distutils/__init__.py", line 19, in <module>
import dist
ImportError: No module named dist
Run Code Online (Sandbox Code Playgroud)
相应地distutils,在cxfreeze输出的缺少模块部分中,有几个条目:
? dist imported from distutils
? distutils.ccompiler imported from numpy.distutils.ccompiler
? distutils.cmd imported from setuptools.dist
? distutils.command.build_ext imported from distutils
? distutils.core imported from numpy.distutils.core
...
Run Code Online (Sandbox Code Playgroud)
我尝试通过将distutils导入到我的主python文件中并将其添加到cxfreeze中,将distutils作为模块包括在内setup.py:
options = {"build_exe": {"packages" : ["distutils"]} },
Run Code Online (Sandbox Code Playgroud)
两种方法均无效。好像我已经以某种方式破坏了virtualenv [因为distutils看起来很基本,并且关于distutils的位置的警告],重复使用干净的virtualenv可以重复此问题。
可能值得注意的是,我通过运行安装了cx-freeze,$VIRTUAL_ENV/build/cx-freeze/setup.py install因为它不能在pip中干净地安装。
找到了另一个解决方法,使您可以在冻结时仍然使用virtualenv。
解决方法是排除distutils,并手动从原始解释器(而不是virtualenv)添加软件包。
# contents of setup.py
from cx_Freeze import setup, Executable
import distutils
import opcode
import os
# opcode is not a virtualenv module, so we can use it to find the stdlib; this is the same
# trick used by distutils itself it installs itself into the virtualenv
distutils_path = os.path.join(os.path.dirname(opcode.__file__), 'distutils')
build_exe_options = {'include_files': [(distutils_path, 'distutils')], "excludes": ["distutils"]}
setup(
name="foo",
version="0.1",
description="My app",
options={"build_exe": build_exe_options},
executables=[Executable("foo_main.py", base=None)],
)
Run Code Online (Sandbox Code Playgroud)
感谢Bruno Oliveira在github上的
答案要点完整答案:https : //gist.github.com/nicoddemus/ca0acd93a20acbc42d1d
总结我的评论:
distutilsvirtualenv 中的副本正在做一些奇怪的事情,这让 cx_Freeze 感到困惑。简单的解决方法是在 virtualenv 外部冻结,以便它使用 distutils 的系统副本。
在 Ubuntu 上,Python 2 和 3 可以愉快地共存:只需使用python3Python 3 执行任何操作即可。例如,在 Python 3 下安装 cx_Freeze:python3 setup.py install。
| 归档时间: |
|
| 查看次数: |
3924 次 |
| 最近记录: |