我刚刚创建了一个小的 GUI 程序,它可以在 IPython 中编译并正常工作,但是当我尝试使用 pyinstaller 将它导出到 .exe
时,它给我一个导入错误。我确定它是 sklearn
,因为当我注释掉 sklearn
导入时,我的文件在构建时可以正常打开。
C:\Users\Chris\Anaconda>C:/Users/Chris/Anaconda/dist/Room_Test.exe
WARNING: file already exists but should not: C:\Users\Chris\AppData\Local\Temp\_MEI100402\Include\pyconfig.h
Traceback (most recent call last):
File "<string>", line 9, in <module>
File "C:\Users\Chris\Anaconda\Lib\site- packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Chris\Anaconda\build\Room_Test\out00- PYZ.pyz\sklearn.neighbors", line 6, in <module>
File "C:\Users\Chris\Anaconda\Lib\site- packages\PyInstaller\loader\pyi_importers.py", line 409, in load_module
module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
File "dist_metrics.pxd", line 48, in init sklearn.neighbors.ball_tree (sklearn\neighbors\ball_tree.c:35726)
File "C:\Users\Chris\Anaconda\Lib\site- packages\PyInstaller\loader\pyi_importers.py", line 409, in load_module
module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
File "dist_metrics.pyx", line 52, in init sklearn.neighbors.dist_metrics (sklearn\neighbors\dist_metrics.c:25494)
ImportError: No module named typedefs
最佳答案
您仍然可以通过在命令中添加以下内容来使用 pyinstaller:
--hidden-import sklearn.neighbors.typedefs
或将以下内容添加到您的 .spec
文件中:
hiddenimports=['cython', 'sklearn', 'sklearn.neighbors.typedefs']
关于python - 为什么在使用 pyinstaller 构建 .exe 时出现 ImportError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31774906/