[英]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.我正在使用
pyinstaller
将.py
转换为.exe
但是在转换后,当我运行.exe
,命令行窗口会突然弹出并关闭。 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: .exe 几乎完全不起作用,然后我导航到
warn.txt
文件,它说有一堆丢失的模块:
missing module named resource
missing module named posix
missing module named _posixsubprocess
missing module named cv2
and allot more ( 24 in total )并分配更多(共 24 个)
I've researched this problem and could not get a good answer iv tried converting with --onefile
and --onedir
and the same thing happens.我已经研究过这个问题,但无法得到一个好的答案 iv 尝试使用
--onefile
和--onedir
转换,但同样的事情发生了。
how do I import or fix these missing modules so that the .exe
will run correctly or even at all?我如何导入或修复这些丢失的模块,以便
.exe
能够正确运行甚至根本运行?
Try to make a spec file and use hidden_imports for the modules you are missing:尝试制作一个规范文件并为您缺少的模块使用 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')
Then run pyinstaller main.spec
.然后运行
pyinstaller main.spec
。
Make sure to run the correct pyinstaller if you're using a virtual env.如果您使用的是虚拟环境,请确保运行正确的 pyinstaller。 You need to use the one that is installed in that specific venv.
您需要使用安装在该特定 venv 中的那个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.