我是靠谱客的博主 健壮豆芽,这篇文章主要介绍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:内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复