DLL load failed when importing PyQt5

2019-01-06 17:09发布

问题:

I have installed PyQt5 on windows platform and and getting an importError: DLL load failed.

I have installed pyqt5 using the command

pip3 install pyqt5
Successfully installed pyqt5-5.8.1

My Python version is as follows:

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

回答1:

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).

If your Python distro doesn't bundle python3.dll, you can try one from WinPython (https://winpython.github.io/).

At least the 2017/04/01 versions should have it.

1) Download WinPython ('Zero' version suffices; must be same "main version" - 3.5/3.6 -and "bitness" - 32/64 - as your Python !!!).

2) Extract to some temp directory, take the python3.dll and stick it into your python dir, next to the python3x.dll.

3) Enjoy working QT



回答2:

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:

pip install PyQT5==5.9

and it has solved the issue.



回答3:

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.



回答4:

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.

I switched to using no virtualenv, and installed PyQt5 in the global Python dir. That fixed it.



回答5:

In Windows 10 using Python 3.6 I fixed this error going through the following steps:

1) Install PyQt5 with pip install pyqt5

2) As explained in this Microsoft website, I modified my Visual Studio 2017 Community installation enabling "Python native development tools"

3) Copy python3.dll from C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64 to C:\IntelPython3\Lib\site-packages\PyQt5 (check your directory)



回答6:

You can try downloading 64bit Python Installer (Windows x86-64 executable installer) from here. I am using PyQt5==5.10.1. Solve my problem.



回答7:

I tried all the solutions here and some of ones elsewhere, however any of them did not work for me. Solution that worked for me is to install a newer Python version.