如问题中所详述,在conda控制台中启动捆绑的应用程序时,它可以正常运行,由导出的所有已加载DLLProcessExplorer
都位于pyinstaller创建的dist dir中。因此,问题在于包含pyqt DLL的路径不在系统PATH
环境中。也许这是pyinstaller的错误。解决方法是PATH
手动将程序路径添加到系统环境中。
这是我正在使用的代码片段:
# Fix qt import error
# Include this file before import PyQt5
import os
import sys
import logging
def _append_run_path():
if getattr(sys, 'frozen', False):
pathlist = []
# If the application is run as a bundle, the pyInstaller bootloader
# extends the sys module by a flag frozen=True and sets the app
# path into variable _MEIPASS'.
pathlist.append(sys._MEIPASS)
# the application exe path
_main_app_path = os.path.dirname(sys.executable)
pathlist.append(_main_app_path)
# append to system path enviroment
os.environ["PATH"] += os.pathsep + os.pathsep.join(pathlist)
logging.error("current PATH: %s", os.environ['PATH'])
_append_run_path()