我有一个使用Pyinstaller的已建立的Python应用程序的构建脚本。这个脚本已经运行了一年多了。然后今天,我在这个应用程序的源文件中添加了一行
import scipy.stats
因为我想使用scipy.stats.linregress。现在,这会导致构建脚本崩溃,并带有长错误回溯(显然是通过一系列相互导入的模块返回),以
结尾 File "C:\Users\462974\Documents\Local Sandbox\fof\TRUNK\programs\CDFParsing\build\pyi.win32\CDFGUI\outPYZ1.pyz/scipy.sparse.csgraph", line 148, in <module>
File "C:\Python27\pyinstaller-1.5\iu.py", line 436, in importHook
mod = _self_doimport(nm, ctx, fqname)
File "C:\Python27\pyinstaller-1.5\iu.py", line 495, in doimport
mod = importfunc(nm)
File "C:\Python27\pyinstaller-1.5\iu.py", line 297, in getmod
mod = owner.getmod(nm)
File "C:\Python27\pyinstaller-1.5\archive.py", line 468, in getmod
return iu.DirOwner.getmod(self, self.prefix+'.'+nm)
File "C:\Python27\pyinstaller-1.5\iu.py", line 109, in getmod
mod = imp.load_module(nm, fp, attempt, (ext, mode, typ))
File "_shortest_path.pyx", line 18, in init scipy.sparse.csgraph._shortest_path (scipy\sparse\csgraph\_shortest_path.c:14224)
File "C:\Python27\pyinstaller-1.5\iu.py", line 455, in importHook
raise ImportError, "No module named %s" % fqname
ImportError: No module named scipy.sparse.csgraph._validation
这很令人费解,因为位于C:\ Python27 \ Lib \ site-packages \ scipy \ sparse \ csgraph_validation.py的模块非常存在。为什么在我的构建中添加scipy会破坏它(导入numpy工作得很好),它可能无法找到它吗?
答案 0 :(得分:1)
不完全确定原因,但在import语句修复后我的代码中包含以下定义:
def fix_dependencies():
from scipy.sparse.csgraph import _validation