27
votes

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

15
I have uninstalled this and installed 5.6 from conda install --channel https://conda.anaconda.org/bpentz pyqt5 and didn't get the error. - gdRow
does it show with pip list? - Aaron
Yes it does @Aaron - gdRow
do you have multiple instances of python? - Aaron
after installing with conda (which was successful?) open an interpreter, import PyQt5, and call PyQt5.__file__ to get the location conda put it. then go to a command prompt, and after installing 5.8.1 with pip, call pip show pyqt5 and compare the location to that of 5.6 you installed with conda. If the path to /site-packages/ is different, you have multiple separate installations. - Aaron

15 Answers

29
votes

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

14
votes

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.

7
votes

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.

3
votes

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:

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

Never use --no-cache-dir since it will produce an assert error when installing the whl file:

assert building_is_possible
assertion Error

I ended up installing 5.10 and had the following error:

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:

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.

TL;DR: I re-ran my python Qt script with UAC elevation, and guess what, it worked !

2
votes

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.

2
votes

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"

enter image description here

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)

2
votes

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)

pip install PySide2==5.14

2
votes

I could manage to fix it for my conda environment (conda 4.6.11, python 3.6) I was struggling with this issue for a long time, trying all the fixes suggested here. In the end, I figured it out! Use pip3 install instead conda install (my conda seems to perform poorly), even in conda environment (pip3, not just pip, pip didn't work for me).

How I found it out? I pip3 install PyQt5==5.9.1, it loaded fine, but the issue with DLL load failed moved to the other library, like PIL, so I did the same installed it with pip3 and then I had to reinstall each library with pip3 and now it works.

1
votes

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.

1
votes

Solution

  1. Close all programs & compilers
  2. Open Anaconda Navigator Make sure you have installed pyqt and qtpy modules (qtawesome optional)
  3. From Anaconda Navigator Home and launch VS code, Jupyter your favored editor
  4. Run your program!-

this is not a permanent fix but it worked for me hope it works for you too @Miloslav Raus answer didn't work for me

1
votes

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 again and ran again.

Worked perfectly. Hope, it helped someone.

1
votes

Update 2020-06

On a newborn Windows 10 64 Pro with a shiny new Python 3.8 64 and pipenv install pyside2 I got the cursed "DLL load failed". The double-verified solution is an underestimated dependency on the Microsoft Visual C++ Runtime. A foolproof installer is available at https://aka.ms/vs/16/release/vc_redist.x64.exe

Versions 5.13 to 5.15 are running out of the box now as soon as the runtime was installed.

Cheers!

0
votes

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

0
votes

If you have tried all/most of the above and still gets no where. Here is the solution.

Firstly, exclude the virtual environment issues by checking the PyQt5 path. Open a Windows terminal, and type below

python
import PyQt5
PyQt5.__file__

Now that you have seen the PyQt5 path that the default python recognizes (before __init__.py), check that in File Browser and you should find the PyQt5 directory. It is fine, and the DLL import error is not due to this issue!

If the DLL cannot be imported problem persists, it is because your Windows lacks higher Visual C++ runtime environment. Yes, PyQt5 for Windows is built on Visual C++ 2015-2019. Just download and install that patch to your Windows and restart, problem solved.

-1
votes

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.