gpt4 book ai didi

python - 为什么在使用 pyinstaller 构建 .exe 时出现 ImportError?

转载 作者:太空狗 更新时间:2023-10-29 19:34:07 25 4
gpt4 key购买 nike

我刚刚创建了一个小的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com