Mohit Saxena
Mohit Saxena

Reputation: 81

ModuleNotFound error while executing a package created by PyInstaller On Windows

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

Upvotes: 3

Views: 5762

Answers (2)

Masoud Rahimi
Masoud Rahimi

Reputation: 6051

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

Upvotes: 0

Nsikan Sylvester
Nsikan Sylvester

Reputation: 618

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

Upvotes: -2

Related Questions