您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

pyinstaller捆绑python应用程序后,如何修复“ ImportError:在PATH上找不到Qt5Core.dll”

pyinstaller捆绑python应用程序后,如何修复“ ImportError:在PATH上找不到Qt5Core.dll”

如问题中所详述,在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()
python 2022/1/1 18:45:30 有572人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶