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

标签 python ipython scikit-learn pyinstaller py2app

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

相关文章:

date - 我无法将 csv 文件中的日期信息解析为 ipython

python-2.7 - OnVsRestClassifier 给出 0 准确率

python - 为 CountVectorizer (sklearn) 添加词干支持

python - 我的python代码出现问题

exception - 简单的 IPython 示例在 sys.exit() 上引发异常

python - Cefpython GetText() 函数

ipython - 在 IPython qtconsole 中启用 vi 键绑定(bind)

Python - 输入包含 NaN、无穷大或对于 dtype ('float64' 来说太大的值)

python - 检查 float 是否等于python中的整数值

python - 从 Django 登录中检索 SQL 条目