Traceback (most recent call last): File "demo.py", line 3, in <module> File "d:\python project\demo\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.__dict__) File "lib\site-packages\PyQt5\__init__.py", line 41, in <module> File "lib\site-packages\PyQt5\__init__.py", line 33, in find_qt ImportError: unable to find Qt5Core.dll on PATH [11632] Failed to execute script demo
出现原因
PyQt5对系统变量的加载存在bug。
解决方法
在主程序中PyQt5库import之前就对系统变量进行手动设置。
import sys, os
ifhasattr(sys, "frozen"): os.environ["PATH"] = sys._MEIPASS + ";" + os.environ["PATH"] from PyQt5 import QtCore, QtWidgets, QtGui from PyQt5.QtWidgets import * from PyQt5.QtGui import *