Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing modules after converting .py to .exe with pyinstaller

I am using pyinstaller to convert .py to .exe however after converting, when I then run the .exe, a command line window pops up for a split second and closes. the .exe isn't working almost at all, I then navigate to the warn.txt file and it says that there are a bunch of missing modules:

missing module named resource
missing module named posix
missing module named _posixsubprocess
missing module named cv2

and allot more (24 in total)

I've researched this problem and could not get a good answer iv tried converting with --onefile and --onedir and the same thing happens.

how do I import or fix these missing modules so that the .exe will run correctly or even at all?

like image 219
Jason Rieder Avatar asked Mar 23 '26 19:03

Jason Rieder


1 Answers

Try to make a spec file and use hidden_imports for the modules you are missing:

# -*- mode: python -*-
import sys
sys.setrecursionlimit(5000)

block_cipher = None
a = Analysis(['src\\main.py'],
         pathex=['your_path_text'],
         binaries=[],
         datas=[],
         hiddenimports=['cv2','your_missing_modules...'],
         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='main',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='main')

Then run pyinstaller main.spec.

like image 133
Sebastian R. Avatar answered Mar 26 '26 09:03

Sebastian R.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!