简体   繁体   中英

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?

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 .

Make sure to run the correct pyinstaller if you're using a virtual env. You need to use the one that is installed in that specific venv.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM