使用scipy模块的一个小python脚本执行得很好,但是当使用pyinstaller编译独立的可执行文件时,可执行文件会失败。细节: Windows 10 python 2.7.10 pyinstaller 3.3.1 错误消息是:
C:\Users\barry\Desktop\Testing>TestScipy
Traceback (most recent call last):
File "TestScipy.py", line 15, in <module>
from scipy import stats
File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages\scipy\stats\__init__.py", line 343, in <module>
File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages\scipy\stats\stats.py", line 169, in <module>
File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages\scipy\special\__init__.py", line 640, in <module>
File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 687, in load_module
module = imp.load_module(fullname, fp, filename, ext_tuple)
ImportError: DLL load failed: The specified module could not be found.
[9476] Failed to execute script TestScipy
如何确保pyinstaller正确加载scipy?
答案 0 :(得分:0)
您可以将scipy.stats
添加到.spec文件中的hiddenimports
列表中,然后再次运行PyInstaller(pyinstaller myfile.spec
)。或者您可以将以下选项添加到PyInstaller命令中:
pyinstaller [options] --hiddenimport=scipy.stats myfile.py
答案 1 :(得分:0)
pyinstaller查找scipy.stats的问题依赖于所使用的Python安装: Mac OSX:10.13中的原生python没有出现问题 Windows 10:使用Anaconda python消除了这个问题 Ubuntu Linux 16.10:使用Anaconda python解决了这个问题。