我是靠谱客的博主 健壮豆芽,最近开发中收集的这篇文章主要介绍pycharm、pyqt5、pyinstaller打包运行后出现错误ImportError: unable to find Qt5Core.dll on PATH的解决,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

pycharm、pyqt5、pyinstaller打包运行后出现错误ImportError: unable to find Qt5Core.dll on PATH的解决

在 PyQt5.13 中,其 __init__.py 文件内容如下:

# Copyright (c) 2019 Riverbank Computing Limited <info@riverbankcomputing.com>
#
# This file is part of PyQt5.
#
# This file may be used under the terms of the GNU General Public License
# version 3.0 as published by the Free Software Foundation and appearing in
# the file LICENSE included in the packaging of this file.  Please review the
# following information to ensure the GNU General Public License version 3.0
# requirements will be met: http://www.gnu.org/copyleft/gpl.html.
#
# If you do not wish to use this file under the terms of the GPL version 3.0
# then you may purchase a commercial license.  For more information contact
# info@riverbankcomputing.com.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.


def find_qt():
    import os

    path = os.environ['PATH']

    dll_dir = os.path.dirname(__file__) + '\Qt\bin'
    if os.path.isfile(dll_dir + '\Qt5Core.dll'):
        path = dll_dir + ';' + path
        os.environ['PATH'] = path
    else:
        for dll_dir in path.split(';'):
            if os.path.isfile(dll_dir + '\Qt5Core.dll'):
                break
        else:
            raise ImportError("unable to find Qt5Core.dll on PATH")

    try:
        os.add_dll_directory(dll_dir)
    except AttributeError:
        pass


find_qt()
del find_qt

 

从上面可以看到,错误是在 raise ImportError("unable to find Qt5Core.dll on PATH") 这里报出来。这段代码的大致意思就是在系统的环境变量 PATH 路径下去找 Qt5Core.dll 文件,而实际上这个文件并不在 PATH 路径下。

我们在使用 PyInstaller 打包时,指定 -F 选项理论上是会将 Qt5Core.dll 文件打包进可执行文件的,但是由于 PyQT5.13 默认在系统 PATH 路径下查找,因此出错了。

我们可以将下面的内容注释掉,然后一切运行正常。

else:
raise ImportError("unable to find Qt5Core.dll on PATH")
 

最后

以上就是健壮豆芽为你收集整理的pycharm、pyqt5、pyinstaller打包运行后出现错误ImportError: unable to find Qt5Core.dll on PATH的解决的全部内容,希望文章能够帮你解决pycharm、pyqt5、pyinstaller打包运行后出现错误ImportError: unable to find Qt5Core.dll on PATH的解决所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部