Chr*_*ris 9 python ipython pyinstaller py2app scikit-learn
我刚刚创建了一个小的GUI程序,可以在IPython中编译和工作,但是当我尝试将它导出到.exe
使用pyinstaller时,它会给我一个导入错误.我确定这是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
Run Code Online (Sandbox Code Playgroud)
小智 12
您仍然可以通过在命令中添加以下内容来使用pyinstaller:
--hidden-import sklearn.neighbors.typedefs
Run Code Online (Sandbox Code Playgroud)
或者将以下内容添加到您的.spec
文件中:
hiddenimports=['cython', 'sklearn', 'sklearn.neighbors.typedefs']
Run Code Online (Sandbox Code Playgroud)
最好使用spec文件导入另一个隐藏的库可能会导致问题.我列出了所有Sklearn库并添加到spec文件中,作为这样的hiddenimports:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['MyPythonApplication.py'],
pathex=['..\\ApplicationFolder'],
binaries=[],
datas=[],
hiddenimports=['cython', 'sklearn', 'sklearn.ensemble', 'sklearn.neighbors.typedefs', 'sklearn.neighbors.quad_tree', 'sklearn.tree._utils'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='ExeFileName',
debug=False,
strip=False,
upx=False,
console=False )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='ApplicationName')
Run Code Online (Sandbox Code Playgroud)
自己解决了!最终使用 py2exe。尽管 x64 系统尚不支持捆绑到一个 .exe,但导入模块要容易得多。但为我的目的工作。刚刚将以下行添加到“包含”中:
sklearn.neighbors.typedefs
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7954 次 |
最近记录: |