在Windows上执行由PyInstaller创建的软件包时出现ModuleNotFound错误 [英] ModuleNotFound error while executing a package created by PyInstaller On Windows
问题描述
我正在打包我的ML解决方案,其中包括使用PyInstaller的keras和tensorflow. exe构建良好,但是当我执行exe时会给出ModuleNotFoundError for boto
.如果我使用脚本运行该解决方案,效果很好.所有依赖项都已安装.
I am packaging my ML solution which includes keras and tensorflow using PyInstaller. The exe builts just fine but when I execute the exe it gives an ModuleNotFoundError for boto
. The solution works just fine if I run it using the script. All the dependencies were installed.
这是我的规格文件:
block_cipher = None
a = Analysis(['main.py'],
pathex=['.'],
binaries=[],
datas=[('data\\*.tsv', 'data')],
hiddenimports=['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,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='main')
这是错误:
文件"site-packages \ gensim \ utils.py",文件中的第44行 "c:\ programdata \ anaconda3 \ envs \ catalogai \ lib \ site-packages \ PyInstaller \ loader \ pyimod03_importers.py", exec_module中的第627行 exec(字节码,模块. dict )文件"site-packages \ smart_open__init __.py",文件中的第28行 "c:\ programdata \ anaconda3 \ envs \ catalogai \ lib \ site-packages \ PyInstaller \ loader \ pyimod03_importers.py", exec_module中的第627行 exec(字节码,模块. dict )文件"site-packages \ smart_open \ smart_open_lib.py",在第39行中 ModuleNotFoundError:没有名为"boto"的模块[9628]无法执行 脚本主要
File "site-packages\gensim\utils.py", line 44, in File "c:\programdata\anaconda3\envs\catalogai\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.dict) File "site-packages\smart_open__init__.py", line 28, in File "c:\programdata\anaconda3\envs\catalogai\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.dict) File "site-packages\smart_open\smart_open_lib.py", line 39, in ModuleNotFoundError: No module named 'boto' [9628] Failed to execute script main
推荐答案
根据此有时PyInstaller无法找到导入的模块并将其包含在可执行输出中.解决方案很简单:
According to this sometimes PyInstaller cannot find the imported modules and include them in your executable output. The solution is simple:
要查找这些隐藏的导入,请使用
-v
标志(在上面获取Python的详细导入)构建应用并运行它.
To find these hidden imports, build the app with the
-v
flag (Getting Python’s Verbose Imports above) and run it.
一旦知道需要哪些模块,就可以使用--hidden-import=
命令选项,或者通过编辑spec文件,或者使用一个钩子文件,将所需的模块添加到捆绑软件中.(见下文了解PyInstaller钩子).
Once you know what modules are needed, you add the needed modules to the bundle using the --hidden-import=
command option, or by editing the spec file, or with a hook file (see Understanding PyInstaller Hooks below).
只需将缺少的模块添加到hiddenimports
.
Just add your missing modules to hiddenimports
.
block_cipher = None
a = Analysis(['main.py'],
pathex=['.'],
binaries=[],
datas=[('data\\*.tsv', 'data')],
hiddenimports=['sklearn.neighbors.typedefs','sklearn.neighbors.quad_tree','sklearn.tree._utils','boto`],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='main')
这篇关于在Windows上执行由PyInstaller创建的软件包时出现ModuleNotFound错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!