Python 导入 PyQt5 时 DLL 加载失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42863505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DLL load failed when importing PyQt5
提问by gdRow
I have installed PyQt5 on windows platform and and getting an importError: DLL load failed.
我已经在 windows 平台上安装了 PyQt5 并且得到了一个 importError: DLL load failed。
I have installed pyqt5 using the command
我已经使用命令安装了 pyqt5
pip3 install pyqt5
Successfully installed pyqt5-5.8.1
My Python version is as follows:
我的 Python 版本如下:
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
The import Error is as follows:
导入错误如下:
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.
Thanks & Regards
感谢和问候
回答by Miloslav Raus
It is because of missing Python3.dll
(stub dll, that re-exports Python3x.dll
functions, so that one version of extension can work for multiple versions of python).
这是因为缺少Python3.dll
(存根dll,重新导出Python3x.dll
函数,因此一个版本的扩展可以适用于多个版本的python)。
If your Python distro doesn't bundle python3.dll, you can try one from WinPython (https://winpython.github.io/).
如果您的 Python 发行版没有捆绑 python3.dll,您可以尝试使用 WinPython ( https://winpython.github.io/) 中的一个。
At least the 2017/04/01 versions should have it.
至少 2017/04/01 版本应该有它。
1) Download WinPython ('Zero' version suffices; must be same "main version" - 3.5/3.6 -and "bitness" - 32/64 - as your Python !!!).
1) 下载 WinPython(“零”版本就足够了;必须与您的 Python 相同的“主版本” - 3.5/3.6 - 和“位数” - 32/64 !!!)。
2) Extract to some temp directory, take the python3.dll and stick it into your python dir, next to the python3x.dll.
2) 解压到某个临时目录,将 python3.dll 粘贴到您的 python 目录中,在 python3x.dll 旁边。
3) Enjoy working QT
3)享受工作QT
回答by LemurPwned
I know the topic is old but I have also had this problem with the newest version of PyQT 5.11 but I've downgraded it to 5.9 via:
我知道这个话题很旧,但我在最新版本的 PyQT 5.11 上也遇到了这个问题,但我已经通过以下方式将其降级到 5.9:
pip install PyQT5==5.9
and it has solved the issue.
它已经解决了这个问题。
回答by AndreKR
If you created a virtualenv, check if python3.dll
was copied into the Scripts
directory of that virtualenv. Chances are only python35.dll
(or python36.dll
, etc., depending on the Python version) was copied, in which case you would get the error you're getting.
如果您创建了 virtualenv,请检查是否python3.dll
已复制到该Scripts
virtualenv的目录中。只有python35.dll
(或python36.dll
,等等,取决于 Python 版本)被复制的机会,在这种情况下,您会得到您得到的错误。
回答by Stefan Monov
I found an alternative fix.
我找到了一个替代解决方案。
I was using a virtualenv because PyCharm had made one for me and I didn't know better. I had installed PyQt5 in that virtualenv.
我使用的是 virtualenv,因为 PyCharm 为我制作了一个,我不知道更好。我已经在那个 virtualenv 中安装了 PyQt5。
I switched to using no virtualenv, and installed PyQt5 in the global Python dir. That fixed it.
我切换到不使用 virtualenv,并在全局 Python 目录中安装了 PyQt5。那修复了它。
回答by Orsiris de Jong
In my case, I had Windows 10 32-bits and Python 3.7.2. Using PyQt5 5.11 installed via pip I got this error:
就我而言,我有 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.
I noticed that version 5.11 came without Qt DLLs, so I reinstalled an earler version with
python -m pip uninstall PyQt5
and python -m pip install PyQt5==5.10
我注意到,5.11版本不前来Qt的DLL文件,所以我重新安装了早期的版本版本
python -m pip uninstall PyQt5
和python -m pip install PyQt5==5.10
Never use --no-cache-dir since it will produce an assert error when installing the whl file:
切勿使用 --no-cache-dir ,因为它会在安装 whl 文件时产生断言错误:
assert building_is_possible
assertion Error
I ended up installing 5.10 and had the following 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.
After setting QT_DEBUG_PLUGINS and even plugin path with:
设置 QT_DEBUG_PLUGINS 甚至插件路径后:
set QT_DEBUG_PLUGINS=
set QT_PLUGIN_PATH=C:\Python37-32\Lib\site-packages\PyQt5\Qt\plugins
I realised that the dll qwindows.dll was searched in the right path where it resides.
我意识到在它所在的正确路径中搜索了 dll qwindows.dll。
TL;DR:I re-ran my python Qt script with UAC elevation, and guess what, it worked!
TL;DR:我用 UAC 提升重新运行了我的 python Qt 脚本,你猜怎么着,它起作用了!
回答by Travis
This can also happen when you have a version of Anaconda installed which comes with PyQt5 and you overshadow that package with a pip installed version. Uninstalling the pip installed version corrected the problem for me.
当您安装了 PyQt5 附带的 Anaconda 版本并且您使用 pip 安装版本掩盖了该软件包时,也会发生这种情况。卸载 pip 安装版本为我纠正了这个问题。
回答by Rohan Arora
Solution
解决方案
- Close all programs & compilers
- Open Anaconda Navigator Make sure you have installed pyqt and qtpy modules (qtawesome optional)
- From Anaconda Navigator Home and launch VS code, Jupyter your favored editor
- Run your program!-
- 关闭所有程序和编译器
- 打开 Anaconda Navigator 确保你已经安装了 pyqt 和 qtpy 模块(qtawesome 可选)
- 从 Anaconda Navigator Home 启动 VS Code,Jupyter 是你最喜欢的编辑器
- 运行你的程序!-
this is not a permanent fix but it worked for me hope it works for you too @Miloslav Rausanswer didn't work for me
这不是永久性修复,但对我有用,希望对你也有用@Miloslav Raus回答对我不起作用
回答by WMax
I had the same issue.
我遇到过同样的问题。
The problem was that my PySide2 version was different from PyQt5 version (PySide2: 5.12, PyQt5: 5.14). I upgraded PySide2 to 5.14 and it worked for me. (Python 3.6.5)
问题是我的 PySide2 版本与 PyQt5 版本不同(PySide2:5.12,PyQt5:5.14)。我将 PySide2 升级到 5.14,它对我有用。(Python 3.6.5)
pip install PySide2==5.14
pip install PySide2==5.14
回答by aknay
回答by Mujeeb Ishaque
The answer is quite simple sometimes. Went through a lot of headaches because the application was running smoothly before restarting my computer. However, I just said to myself, maybe windows just can't load the DLL module? So I restarted my computer againand ran again.
答案有时很简单。经历了很多麻烦,因为应用程序在重新启动计算机之前运行顺利。然而,我只是对自己说,也许windows只是无法加载DLL模块?所以我再次重新启动我的电脑并再次运行。
Worked perfectly. Hope, it helped someone.
完美地工作。希望,它帮助了某人。