我使用PyInstaller將我的應用程序捆綁到一個.exe文件中。 問題是使用--onedir選項可以正常工作,但使用--onefile生成時無法找到模塊。PyInstaller:一個模塊不包含在--onefile中,但與--onedir正常工作
兩個--onedir並在建設過程中--onefile說:
<...>
INFO: Analyzing hidden import 'sklearn.utils.sparsetools._graph_validation'
<...>
運行與--onedir工作正常創建的實例,但--onefile產生的實例終止:
<...>
File "_min_spanning_tree.pyx", line 8, in init sklearn.utils.mst._min_spanning
_tree (sklearn\utils\sparsetools\_min_spanning_tree.c:4754)
ImportError: No module named _graph_validation
這裏是我的.spec文件
onedir.spec
# -*- mode: python -*-
a = Analysis(['../../brainactivity.py'],
hiddenimports=['greenlet', 'sklearn.utils.sparsetools._graph_validation', 'sklearn.utils.sparsetools._graph_tools', 'scipy.special._ufuncs_cxx', 'sklearn.utils.lgamma', 'sklearn.utils.weight_vector'],
hookspath=None,
runtime_hooks=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='brainactivity.exe',
debug=False,
strip=None,
upx=True,
console=True,)
coll = COLLECT(exe,
a.binaries,
[('./data/201305182224-DF-facial-3-420.csv', '../../data/201305182224-DF-facial-3-420.csv', 'DATA')],
[('./model/brain_20k_colored_properly.obj', '../../model/brain_20k_colored_properly.obj', 'DATA')],
[('brain_fragment_shader.glsl', '../../brain_fragment_shader.glsl', 'DATA')],
[('brain_vertex_shader.glsl', '../../brain_vertex_shader.glsl', 'DATA')],
a.zipfiles,
a.datas,
strip=None,
upx=True,
name='brainactivity')
onefile.spec
# -*- mode: python -*-
a = Analysis(['../../brainactivity.py'],
hiddenimports=['greenlet', 'sklearn.utils.sparsetools._graph_validation', 'sklearn.utils.sparsetools._graph_tools', 'scipy.special._ufuncs_cxx', 'sklearn.utils.lgamma', 'sklearn.utils.weight_vector'],
hookspath='.',
runtime_hooks=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
a.binaries,
[('./data/201305182224-DF-facial-3-420.csv', '../../data/201305182224-DF-facial-3-420.csv', 'DATA')],
[('./model/brain_20k_colored_properly.obj', '../../model/brain_20k_colored_properly.obj', 'DATA')],
[('brain_fragment_shader.glsl', '../../brain_fragment_shader.glsl', 'DATA')],
[('brain_vertex_shader.glsl', '../../brain_vertex_shader.glsl', 'DATA')],
a.zipfiles,
a.datas,
name='brainactivity.exe',
debug=False,
strip=None,
upx=True,
console=True)
對於pyinstaller 3,您必須使用下面的代碼導入** ** collect_submodules: '從PyInstaller.utils.hooks導入collect_submodules' [PyInstaller文檔] (https://pythonhosted.org/PyInstaller/#useful-items-in-pyinstaller-utils-hooks) –
你節省了我的一天謝謝 – x0v