![](/img/trans.png)
[英]How to fix my problem with missing modules when converting .py to .exe with PyInstaller?
[英]missing modules after converting .py to .exe with pyinstaller
我正在使用pyinstaller
將.py
轉換為.exe
但是在轉換后,當我運行.exe
,命令行窗口會突然彈出並關閉。 .exe 幾乎完全不起作用,然后我導航到warn.txt
文件,它說有一堆丟失的模塊:
missing module named resource
missing module named posix
missing module named _posixsubprocess
missing module named cv2
並分配更多(共 24 個)
我已經研究過這個問題,但無法得到一個好的答案 iv 嘗試使用--onefile
和--onedir
轉換,但同樣的事情發生了。
我如何導入或修復這些丟失的模塊,以便.exe
能夠正確運行甚至根本運行?
嘗試制作一個規范文件並為您缺少的模塊使用 hidden_imports:
# -*- 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')
然后運行pyinstaller main.spec
。
如果您使用的是虛擬環境,請確保運行正確的 pyinstaller。 您需要使用安裝在該特定 venv 中的那個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.