导入PyQt5时DLL加载失败

问题描述 投票:19回答:10

我在Windows平台上安装了PyQt5并获得了importError:DLL加载失败。

我已经使用命令安装了pyqt5

pip3 install pyqt5
Successfully installed pyqt5-5.8.1

我的Python版本如下:

Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32

导入错误如下:

from PyQt5.QtWidgets import QApplication
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.

感谢和问候

python python-3.x dllimport pyqt5 importerror
10个回答
22
投票

这是因为缺少Python3.dll(存根dll,重新导出Python3x.dll函数,因此一个版本的扩展可以适用于多个版本的python)。

如果您的Python发行版没有捆绑python3.dll,您可以尝试使用WinPython(https://winpython.github.io/)。

至少2017/04/01版本应该有它。

1)下载WinPython('零'版本足够;必须相同“主版本” - 3.5 / 3.6 - 和“位数” - 32/64 - 作为你的Python !!!)。

2)解压到一些临时目录,取python3.dll并将其粘贴到python目录旁边的python3x.dll中。

3)享受QT工作


0
投票

答案很简单。经历了很多麻烦,因为应用程序在重新启动计算机之前运行顺畅。但是,我只是对自己说,也许windows只是无法加载DLL模块?所以我再次重新启动计算机并再次运行。

工作得很完美。希望,它帮助了一个人。


-1
投票

我尝试了所有解决方案和其他一些解决方案,但是其中任何一个都不适合我。对我有用的解决方案是安装更新的Python版本。


10
投票

我知道这个话题已经过时了但是我最新版本的PyQT 5.11也遇到了这个问题,但是我通过以下方式将它降级为5.9。

pip install PyQT5==5.9

它解决了这个问题。


5
投票

如果您创建了virtualenv,请检查python3.dll是否已复制到该virtualenv的Scripts目录中。机会只有python35.dll(或python36.dll等,取决于Python版本)被复制,在这种情况下你会得到你得到的错误。


2
投票

我发现了一个替代修复。

我使用的是virtualenv,因为PyCharm为我制作了一个,我不知道更好。我在那个virtualenv中安装了PyQt5。

我转而使用没有virtualenv,并在全局Python目录中安装了PyQt5。修好了。


1
投票

就我而言,我有Windows 10 32位和Python 3.7.2。使用通过pip安装的PyQt5 5.11我收到此错误:

from PyQt5.QtWidgets import QApplication
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.

我注意到版本5.11没有Qt DLL,我是否重新安装了python -m pip uninstall PyQt5python -m pip install PyQt5==5.10的早期版本

永远不要使用--no-cache-dir,因为它会在安装whl文件时产生断言错误:

assert building_is_possible
assertion Error

我最终安装5.10并出现以下错误:

qt.qpa.plugin: Could not load the Qt platform plugin "windows" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

设置QT_DEBUG_PLUGINS甚至插件路径后:

set QT_DEBUG_PLUGINS=
set QT_PLUGIN_PATH=C:\Python37-32\Lib\site-packages\PyQt5\Qt\plugins

我意识到dll qwindows.dll是在它所在的正确路径中搜索的。

TL; DR:我用UAC高程重新运行了我的python Qt脚本,猜猜是什么,它有效!


0
投票

在使用Python 3.6的Windows 10中,我通过以下步骤修复了此错误:

1)使用pip install pyqt5安装PyQt5

2)正如this Microsoft website中所解释的,我修改了我的Visual Studio 2017社区安装,启用了“Python原生开发工具”

enter image description here

3)将python3.dllC:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64复制到C:\IntelPython3\Lib\site-packages\PyQt5(查看您的目录)


0
投票

您可以尝试从here下载64位Python安装程序(Windows x86-64可执行安装程序)。我正在使用PyQt5==5.10.1。解决我的问题。


0
投票

如果您安装了PyQt5附带的Anaconda版本,并且您使用pip安装版本覆盖该软件包,也会发生这种情况。卸载pip安装版本为我纠正了这个问题。


0
投票

  1. 关闭所有程序和编译器
  2. 打开Anaconda Navigator确保已安装pyqt和qtpy模块(qtawesome可选)
  3. 从Anaconda Navigator Home开始,推出VS代码,Jupyter是您最喜爱的编辑器
  4. 运行你的程序! -

这不是一个永久的修复,但它对我有用希望它也适合你@Miloslav Raus答案对我不起作用

© www.soinside.com 2019 - 2024. All rights reserved.