ModuleNotFound error while executing a package created by PyInstaller On Windows

前提是你 提交于 2020-03-03 11:44:30

问题


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.

Here is my spec file:

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')

Here is the error:

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


回答1:


According to this sometimes PyInstaller cannot find the imported modules and include them in your executable output. The solution is simple:

To find these hidden imports, build the app with the -v flag (Getting Python’s Verbose Imports above) and run it.

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).

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')



回答2:


Have you try to manually install boto module pip install boto3 boto documentation first have pip installed



来源:https://stackoverflow.com/questions/56088674/modulenotfound-error-while-executing-a-package-created-by-pyinstaller-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!