使用py2exe转换程序和传递选项时出现RuntimeError
RuntimeError when using py2exe to convert program and passing options
我正在尝试使用 py2exe 将 python 程序转换为可执行文件,遵循 tutorial flow. I've created a setup.py as below (using this 示例)。
from distutils.core import setup
import py2exe
options = {
'py2exe': {
'compressed': 1,
'optimize': 2,
'bundle_files': 3, #Options 1 & 2 do not work on a 64bit system
'dist_dir': 'dist', # Put .exe in dist/
'xref': False,
'skip_archive': False,
'ascii': False}}
setup(options=options, zipfile=None, console=['main.py'])
当我在 Anaconda 命令提示符中 运行 python setup.py py2exe
(设置为 运行 a python 3.5 环境)时,我得到以下错误跟踪:
running py2exe
Traceback (most recent call last):
File "setup.py", line 14, in <module>
}, zipfile=None, console=['main.py'])
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\runtime.py", line 173, in analyze
target.analyze(mf)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\runtime.py", line 74, in analyze
modulefinder.run_script(self.script)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 86, in run_script
self._scan_code(mod.__code__, mod)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 394, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 138, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load
self._scan_code(module.__code__, module)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 394, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 138, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 356, in _find_and_load
if module.__code__:
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 637, in __code__
raise RuntimeError("should read __file__ to get the source???")
RuntimeError: should read __file__ to get the source???
我尝试跟踪回溯,但无法找出错误的根源。关于我的问题是什么以及如何解决它有什么建议吗?
看来我的错误与 py2exe 缺少对 python 3.5 的支持有关。我 运行 当我 运行 我的问题中链接的教程中列出的教程示例 (hello world) 时,我 运行 遇到了类似的(尽管不完全相同的错误),这就是我确定问题的方式。
我用 python 3.4 解释器创建了一个新的 Anaconda 环境,并且能够成功地为我的原始应用程序构建一个可执行文件。
我正在尝试使用 py2exe 将 python 程序转换为可执行文件,遵循 tutorial flow. I've created a setup.py as below (using this 示例)。
from distutils.core import setup
import py2exe
options = {
'py2exe': {
'compressed': 1,
'optimize': 2,
'bundle_files': 3, #Options 1 & 2 do not work on a 64bit system
'dist_dir': 'dist', # Put .exe in dist/
'xref': False,
'skip_archive': False,
'ascii': False}}
setup(options=options, zipfile=None, console=['main.py'])
当我在 Anaconda 命令提示符中 运行 python setup.py py2exe
(设置为 运行 a python 3.5 环境)时,我得到以下错误跟踪:
running py2exe
Traceback (most recent call last):
File "setup.py", line 14, in <module>
}, zipfile=None, console=['main.py'])
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\runtime.py", line 173, in analyze
target.analyze(mf)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\runtime.py", line 74, in analyze
modulefinder.run_script(self.script)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 86, in run_script
self._scan_code(mod.__code__, mod)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 394, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 138, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load
self._scan_code(module.__code__, module)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 394, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 138, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 356, in _find_and_load
if module.__code__:
File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 637, in __code__
raise RuntimeError("should read __file__ to get the source???")
RuntimeError: should read __file__ to get the source???
我尝试跟踪回溯,但无法找出错误的根源。关于我的问题是什么以及如何解决它有什么建议吗?
看来我的错误与 py2exe 缺少对 python 3.5 的支持有关。我 运行 当我 运行 我的问题中链接的教程中列出的教程示例 (hello world) 时,我 运行 遇到了类似的(尽管不完全相同的错误),这就是我确定问题的方式。
我用 python 3.4 解释器创建了一个新的 Anaconda 环境,并且能够成功地为我的原始应用程序构建一个可执行文件。