我正在尝试使用 cxfreeze 将以下脚本转换为可执行文件
import datetime
from calendar import monthrange
from tia.bbg import LocalTerminal as Lt
import pandas as pd
from pypyodbc import connect, DatabaseError
print 'Hello World!'
在命令行中运行以下行时:
cxfreeze test_freeze.py --target-dir test_freeze
我得到以下回溯
Traceback (most recent call last):
File "C:\Python27\Scripts\cxfreeze", line 5, in <module>
main()
File "C:\Python27\lib\site-packages\cx_Freeze\main.py", line 188, in main
freezer.Freeze()
File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 621, in Freeze
self._FreezeExecutable(executable)
File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 225, in _FreezeExecutable
exe.copyDependentFiles, scriptModule)
File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 602, in _WriteModules
path = os.pathsep.join([origPath] + module.parent.path)
TypeError: can only concatenate list (not "NoneType") to list
令人惊讶的是,该文件仍然被创建,但运行时我得到了这个回溯:
C:\Python27\Scripts\test_freeze>test_freeze.exe
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "test_freeze.py", line 3, in <module>
File "C:\Python27\lib\site-packages\tia\bbg\__init__.py", line 1, in <module>
from tia.bbg.v3api import *
File "C:\Python27\lib\site-packages\tia\bbg\v3api.py", line 5, in <module>
import pandas as pd
File "C:\Python27\lib\site-packages\pandas\__init__.py", line 18, in <module>
raise ImportError("Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
有趣的事情要注意:
我成功运行了一次(使用真正的非“hello world”代码)并且编译成功,我出于数据库目的更改了一个字符串,但收到了此错误。
当我注释掉 tia.bbg 导入和 pandas 导入时,错误停止并且程序成功卡住。注释掉 tia 也很重要,因为它是围绕 pandas 构建的包装器,所以这是有道理的。我可以自信地说 tia 不是问题,因为仅评论 out 就会引发相同的 pandas/numpy 相关错误
我使用的是 Windows 10 64 位、Python 2.7.12 64 位 amd、Pandas 0.18.1,其他相关的也是最新版本,因为我刚刚安装了 Python 和所有模块来避免此问题。它在之前的安装中多次运行,但随后出现了相同的错误。
我的问题是如何让这个脚本正确运行,否则我可以使用哪些模块来实现相同的目标?
最佳答案
我遇到了这个问题。您可以显式排除所有有问题的模块,但通过调试,我想我找到了负责任的代码和一个小错误修复:)。以下内容应该可以帮助您解决这个问题(并且可能会引导您找到下一个缺少的依赖项;))
检查freeze.py的代码,有一个情况没有检查,所以我对freeze.py做了如下修改:
第 600 行,来自
try:
if module.parent is not None:
path = os.pathsep.join([origPath] + module.parent.path)
os.environ["PATH"] = path
self._CopyFile(module.file, target, copyDependentFiles)
finally:
os.environ["PATH"] = origPath
至:
try:
if module.parent is not None:
if module.parent.path is not None:
path = os.pathsep.join([origPath] + module.parent.path)
os.environ["PATH"] = path
self._CopyFile(module.file, target, copyDependentFiles)
else:
path = os.pathsep.join([origPath, os.path.dirname(module.parent.file)])
os.environ["PATH"] = path
print '========================================================'
finally:
os.environ["PATH"] = origPath
关于python - 当 pandas 是导入时,Cx_freeze TypeError 只能使用 numpy 依赖项连接列表(不是 "NoneType")来列出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39007134/