![](/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.