DLL load failed when importing PyQt5
Asked Answered
G

30

41

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

Group answered 17/3, 2017 at 17:14 Comment(10)
I have uninstalled this and installed 5.6 from conda install --channel https://conda.anaconda.org/bpentz pyqt5 and didn't get the error.Group
does it show with pip list?Apograph
Yes it does @ApographGroup
do you have multiple instances of python?Apograph
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.Apograph
@Apograph Both of them have the same /site-packages/. Continuum\\Anaconda3\\lib\\site-packages\\PyQt5\\__init__.pyGroup
I'm not sure then.. it's possible you haven't managed to completely uninstall old versions with pip causing a conflict. be sure to clear pip's cache after uninstalling maybe?Apograph
@Apograph What should I do if the two locations are different? Should I remove one of them?Dominickdominie
@Dominickdominie then you have 2 different installations of python. If you have MacOS or Linux, one of them may be part of the OS, and you shouldn't try to get rid of it. In that case you must be conscious that you are targeting the correct installation when installing libraries. I typically run windows, and when I update to the latest version of python, I delete the old version.Apograph
So I guess coming here in early 2024, and reading many unique (and likely brittle) solutions, is it safe to say PyQt just does not officially support virtual environments?Tiphani
A
34

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

Aculeate answered 27/3, 2017 at 11:32 Comment(4)
Solved my issue with PyQt5 and a virtualenv (windows) - using the python3.dll from the python3.5 installation (copied from c:\python35 to virtualenv\scripts\python3.dll solved that issue)Moncrief
This is the only answer that worked for me for PyQt5 v5.9 with Anaconda 4.4 Python 3.6. Thank you.Sergo
Solved my problem for Python3.5 Anaconda installation.Donndonna
Tried and my interpreter crashed with this error message: fatal python error pythreadstate_get no current when I tried to do a from PyQt5 import to verify if it worksAdulteress
M
15

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.

Mychal answered 13/8, 2018 at 11:29 Comment(1)
I think they have officially deprecated PyQT5<5.10.1 from pip. Using PyQT5==5.10.1 solved my issue.Warwickshire
K
7

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.

Kreg answered 6/11, 2017 at 18:50 Comment(1)
This answer turned out to be the most correct. In my case, it was not enough Python3.dll. But besides that I had to introduce environment variables # -- coding: utf-8 -- import os os.environ['QT_DEBUG_PLUGINS'] = '1' os.environ['QT_PLUGIN_PATH']='C:\\K3-PKM-80\\Data\\PKM\\Proto\\site-packages\\PyQt5\Qt\plugins' import PyQt5 from PyQt5.QtWidgets import (QApplication,)Connotation
U
5

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.

Unsnap answered 30/6, 2019 at 8:9 Comment(1)
I constantly run into Windows / Python DLL errors that fix when I restart.Doge
N
4

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 !

Negotiation answered 22/1, 2019 at 20:15 Comment(0)
X
3

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.

Xenolith answered 3/2, 2021 at 10:27 Comment(1)
This solved it for me. I hate how often this works ^^Sphygmograph
C
2

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)

Cess answered 18/9, 2018 at 8:2 Comment(1)
So you doubt if Visual Studio ruined the original link?Dowell
H
2

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

Hohenstaufen answered 25/12, 2019 at 13:2 Comment(0)
M
2

Update in 2022:

After looking at the comments around the DLL issue, none were recent, and I happened to figure out why this issue still persists. The current version as of writing for PyQt5 is 5.15.6. 5.15.6, 5.15.5 and 5.15.4 give the DLL issue. Not sure how to fix it but to downgrade to 5.15.3.

Actually I never upgraded PyQt5 because I probably had a similar issue somewhere else. But when I installed PyQtWebEngine, it automatically upgraded to latest PyQt5, and required atleast PyQt version 5.15.4 (which gives the DLL error). The way I solved this second issue was to downgrade from PyQtWebEngine-5.15.5 to PyQtWebEngine-5.15.3.

In summary for those that need:

  1. PyQt5 to work:

pip install PyQt5==5.15.3

  1. PyQt5 and PyQtWebEngine

pip install PyQt5==5.15.3

pip install PyQtWebEngine==5.15.3

Mb answered 31/3, 2022 at 5:45 Comment(0)
P
2

I know the question is for PyQT5 but this is the top post when searching for this same issue in PyQT6. So this answer is for anyone looking for a solution in PyQT6.

I found that the issue happens when using PyQT6 version 6.1.0. Upgrading PyQT6 to the latest version (6.3.0 as of writing this answer) resolves this issue. I noticed my project had a dependency on PyQT6-Tools which downgrades the installation of PyQT6 from 6.3.0 -> 6.1.0.

My solution was to remove project dependency from PyQT6-Tools and reinstall PyQT6 this installs the latest version again. Another way is to install PyQT6 then install PyQT6-Tools and then upgrade PyQT6. I checked QTDesigner which works fine not sure about pyuic.

Postulate answered 2/6, 2022 at 6:33 Comment(3)
This was exactly the issue I ran into, thank you.Renascent
for those using PyQt6, this might be the solutionEmplace
I am using PyQt6 (6.5.3) and have this issue.Tiphani
G
2

... reinstall the PyQt5 python package with this argument --ignore-installed:

pip3 install PyQt5 --user --ignore-installed
Gherardi answered 25/1, 2023 at 16:16 Comment(3)
Could you explain what it does? It solved my issue and I can't explain why...Katelin
@Katelin pip (or pip3) install PyQt5 installs PyQt5. --user --ignore-installed means to ignore the fact that it's already installed - the package is replaced with the new oneEldrida
#51913861Lied
B
1

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.

Beverle answered 20/1, 2018 at 11:32 Comment(0)
S
1

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.

Smtih answered 26/2, 2019 at 17:59 Comment(0)
A
1

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

Atheling answered 30/3, 2019 at 20:19 Comment(0)
R
1

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 Fastest and easiest installation method:

winget install Microsoft.VCRedist.2015+.x64

Reefer answered 17/6, 2020 at 6:30 Comment(1)
BTW, version 5.12 is built on Visual C++ 2015-2019 too. You cannot downgrade to version 5.12 to solve the problem.Dowell
D
1

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.

Dowell answered 15/3, 2021 at 3:19 Comment(0)
S
0

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

Sorilda answered 6/12, 2018 at 9:14 Comment(0)
H
0

In Windows 10, it's build-in python 3.7. And it seems too minimalistic.

Try uninstall it and install python3 from python.org

Then you should reinstall pyqt5 for new python.

Housewarming answered 22/7, 2021 at 14:43 Comment(0)
V
0

Recently had this problem on a machine running on an old version of Python. The solution was to import every pyqt5 related modules before doing any other imports.

Vesicle answered 12/8, 2021 at 10:9 Comment(0)
D
0

My PyQt5 was throwing this "module not found" error on 'from PyQt5 import QtGui'

When I reinstalled PyQt5, Pip threw an error traceback that started at:

  • ValueError: Unable to find resource t64.exe in package pip._vendor.distlib

A quick check for t64.exe in Python\lib\site-packages\pip_vendor\distlib\ (the path given in the error message, but with dots) confirmed no t64.exe file.

Fortunately, I had a project distribution archived that had the t64.exe file, so I copied it over to my machine's C:\Program Files\Python directory and that handled the problem.

NOTE: I've been working on this since Windows crashed on startup yesterday and a VERY DICEY system recovery mangled my Python installation. I wiped out my entire Python installation and reinstalled it at least twice, running 'pip --upgrade' each time. One certainly wonders why the t64.exe file got dropped from the installation--and why a reinstall didn't restore it...

Dia answered 5/10, 2021 at 13:4 Comment(0)
E
0

If anyone stumbles on this and is tempted to change their software...first try this simple fix which worked for me. Reboot first before you try anything else then try XSeg editing again.

Engraving answered 17/1, 2022 at 9:58 Comment(1)
then try XSeg editing *again* What is XSeg?Filagree
B
0

I uninstall these packages and reinstall pyqt5 fix

pip uninstall pyqt5
pip uninstall pyqt5-sip
pip uninstall pyqt5-qt5

pip install pyqt5
Bronchia answered 8/9, 2022 at 6:21 Comment(0)
G
0

My workaround to this problem was uninstalling and reinstalling PyQt.

  1. use pip list to list all the installed packages.
  2. uninstall everything that related to the PyQt with pip uninstall (not just pyqt).
  3. Install PyQt again without using the cache like pip install --no-cache-dir pyqt6

This worked for me.

German answered 16/9, 2022 at 5:27 Comment(1)
pyqt6? What if you need pyqt5?Filagree
H
0

I faced same issue while using GUI with GNU Radio. The error message for me is DLL load failed while importing QtCore: The specified procedure could not be found. I installed GNU Radio in its own environment but I am trying to launch it from windows start menu, so I am facing this issue. One time I started the same flow graph by launching the GNU Radio from the environment and then no issues. I manually launched Anaconda prompt and activated the environment where I installed GNU Radio and the error is gone.

Homoeroticism answered 20/1, 2023 at 13:9 Comment(0)
E
0

In case none of these options work, try this (which was exactly my situation). It definitely works on Pycharm, but I'm not sure about other text editors/IDEs.

Pycharm has 2 site-packages under External Libraries(Python version)\Libs. The first one is the library root (says in orange), and the second is standard. For me, if you look at the PyQt5 sub-directory, the library root has many sub-directories, while the other one has just qsci plus some python files. If you open the __ init __.py in the second one, the find_qt function looks like this:

def find_qt():
    import os, sys

    qtcore_dll = '\\Qt5Core.dll'

    dll_dir = os.path.dirname(sys.executable)
    if not os.path.isfile(dll_dir + qtcore_dll):
        path = os.environ['PATH']

        dll_dir = os.path.dirname(__file__) + '\\Qt5\\bin'
        if os.path.isfile(dll_dir + qtcore_dll):
            path = dll_dir + ';' + path
            os.environ['PATH'] = path
        else:
            for dll_dir in path.split(';'):
                if os.path.isfile(dll_dir + qtcore_dll):
                    break
            else:
                return

        try:
            os.add_dll_directory(dll_dir)
        except AttributeError:
            pass


find_qt()
del find_qt

There are also lots of DLL files there. Now here's the trick: copy paste all of these files into the Library Root. If you need things other or more than QtCore (e.g. QtWidgets or QtGui), edit the find_qt() function in __ init __:

def find_qt(qt):
    import os, sys

    qt_dll = f'\\Qt5{qt}.dll' # New in Python 3.6, use string concatenation if using <3.6

    dll_dir = os.path.dirname(sys.executable)
    if not os.path.isfile(dll_dir + qt_dll):
        path = os.environ['PATH']

        dll_dir = os.path.dirname(__file__) + '\\Qt5\\bin'
        if os.path.isfile(dll_dir + qt_dll):
            path = dll_dir + ';' + path
            os.environ['PATH'] = path
        else:
            for dll_dir in path.split(';'):
                if os.path.isfile(dll_dir + qt_dll):
                    break
            else:
                return

    try:
        os.add_dll_directory(dll_dir)
    except AttributeError:
        pass

find_qt("Core")
find_qt("Gui")
find_qt("Widgets")
# And all the other stuff you need

del find_qt
Eldrida answered 11/4, 2023 at 19:4 Comment(0)
G
0

@tom-mike pointed me in the right direction: when installing PyQt (in my case PyQt6) other (sub)packages are installed along the way. But if we do not specify any version for them it seems pip is taking the latest version. In my case (installing PyQt6==6.5.3) I ended up with:

PyQt6 in version 6.5.3 and PyQt6-qt6 in version 6.6.0.

To solve this I uninstalled PyQt via

pip uninstall PyQt6 PyQt6-qt6 PyQt6-sip

and reinstalling with the PyQt6-qt6 additionally set to the same version as PyQt:

pip install pyqt6==6.5.3 pyqt6-qt6==6.5.3

Galcha answered 22/11, 2023 at 11:1 Comment(0)
S
-1

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.

Spillage answered 20/10, 2018 at 12:24 Comment(0)
H
-1

Don't use pip to install PyQt5!!

Just uninstall all your pip PyQt5 and use conda install -c anaconda pyqt

Harm answered 12/7, 2022 at 8:44 Comment(4)
Besides, the pyqt5-tools will also be installed if you use the condaHarm
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Weird
"Don't use pip to install PyQt5" - why not? This would be a better answer if it explained why using pip to install PyQt5 is bad, and why using conda is better.Silvern
because it will lack some packages if you use the pip to install, however, the conda will install all you need and find the right versionHarm
R
-1

I had same problem with importing PySide6.QtWidgets and PyQt6 so i tryed many many different ways to solve it then i updated my windows (10) version and it solved.

Rustyrut answered 18/7, 2023 at 20:7 Comment(0)
D
-1

For me, the following procedure works!

  1. pip uninstall PyQt6 -y
  2. manually delete pyqt6 related folders under \Python\PythonXY\Lib\site-packages
  3. pip install PyQt6
Discredit answered 27/10, 2023 at 9:11 Comment(2)
the question is about PyQt5Eldrida
@Eldrida Works the sameDiscredit

© 2022 - 2024 — McMap. All rights reserved.