Solve – DLL load failed when importing PyQt5

Solve – DLL load failed when importing PyQt5 is a Python error which occurs when there is a problem with Python3.dll.

In this Blog post I am going to solve the error ‘DLL load failed when importing PyQt5’ while I try to investigate why the error is happening in the first place.

I will also introduce some solutions which have worked for other developers and we will see if those solutions can solve the error in your unique situation.

Explaining the Error : DLL load failed when importing PyQt5

The error you have, should have an error message that looks like something like this.

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

The error happens because Python3.dll is missing.

In the sections bellow we will explain the root of the error more and propose some possible fixes.

Solution 1 : Downgrading PyQt

The first solution is a quick fix which can work sometimes, the fix is simple you should try downgrading to a previous version of PyQT.

To do that you can use the command bellow.

                                                                       #
pip install PyQT5==<your-version> # for PyQT5 5.7 the code is : pip install PyQT5==5.7
                                                                       #

This can solve the issue for some people, if this did not work for you or if you do not want to downgrade you can check the solutions bellow.

Solution 2 : Add Python3.dll

The issue is clear, your Python3.dll file is missing, in order to get it, we will use WinPython to get it.

You can google ‘WinPython’ head to their github and download it.

Now, unzip WinPython and extract it to a folder, look for Python3.dll. Copy the file and past it to the Python directory you are working on.

This should be more than enough to solve the problem.

Solution 3 :

Sometimes you create a virtualenv and it results in this error.

You should go to the Scripts directory, then check if Python3.dll was copied to your Scripts directory.

If that is not the case then you should copy it manually.

This should be enough to get rid of the error forever.

Summing-up

This is the end of the article, the error DLL load failed when importing PyQt5 could be confusing but with a little bit of investigating the error could be solved, thanks for reading our blog post and good luck.

If you want to support us consider donating to our Kofi account using the red button on top of this page. Keep coding, keep learning Python and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/