从IDLE执行时我的代码工作完全正常。我用cx_Freeze编译我的Python代码转换成可执行应用程序,现在,它不会运行。我下面将我的“setup.py”的代码。我还提供了从运行命令提示符程序的结果。
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = r'C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Python36_64\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Python36_64\tcl\tk8.6'
build_exe_options = {"packages": ["numpy"]}
setup(name= 'Current-Translator',
version = '1.0',
description = 'Convert and plot electrical current data from data logger.',
options = {"build_exe": build_exe_options},
executables = [Executable('Current-Translator.py')])
命令提示符输出
Traceback (most recent call last):
File "C:\Users\jchoujaa\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\Users\jchoujaa\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "Current-Translator.py", line 6, in <module>
File "C:\Users\jchoujaa\AppData\Local\Programs\Python\Python37\lib\site-packages\timedelta\__init__.py", line 9, in <module>
@public.add
File "C:\Users\jchoujaa\AppData\Local\Programs\Python\Python37\lib\site-packages\public\__init__.py", line 65, in add
return _add(_caller_modules()[1], objects)
IndexError: list index out of range
build_exe
选项安装脚本:
build_exe_options = {"packages": ["numpy", "public", "timedelta"]}
cx_Freeze
与Python 3.7,显然没有进一步的问题。 cx_Freeze
尚不支持的Python 3.7,它有一个bug(仅适用于某些系统配置?)。一个缺陷修复存在,但尚未公布,但可以手动应用它,看到What could be the reason for fatal python error:initfsencoding:unable to load the file system codec?和Cx_freeze crashing Python3.7.0。或者你可以回滚到Python 3.6,如果这是一个选择。