Fix ImportError: unable to find Qt5Core.dll on PATH Error: A Completed Guide – PyQT Tutorial

By | November 22, 2019

We will use pyqt to develop our python ui application, however, we find this error: ImportError: unable to find Qt5Core.dll on PATH. In this tutorial, we will introduce you how to fix this problem.

Fix unable to find Qt5Core.dll on PATH Error

Open PyQT5\__init__.py

You will see source code like this:

dll_dir = os.path.dirname(__file__) + '\\Qt\\bin'
    print(dll_dir)
    if os.path.isfile(dll_dir + '\\Qt5Core_conda.dll'):
        path = dll_dir + ';' + path
        os.environ['PATH'] = path

Print out dll_dir, in our environment, it is:

C:\Users\fly165\.conda\envs\py3.7\lib\site-packages\PyQt5\Qt\bin

Because we install pyqt using anaconda, we will notice where is file ‘Qt5Core_conda.dll‘.

Anaconda Install PyQT: A Completed Guide

From code above, this file should be in C:\Users\fly165\.conda\envs\py3.7\lib\site-packages\PyQt5\Qt\bin, however, it is not?

Where is Qt5Core_conda.dll?

We will search this file with everything (a file search engine).

qt5core_conda.dll installation path

From above, we find this file is installed into: C:\Users\fly165\.conda\pkgs\qt-5.12.5-h7ef1ec2_0\Library\bin

Check the version we have installed qt

conda install pyqt 5.12.5

Comparing with them, we find qt-5.12.5 is not installed into our python environment by anaconda, it is installed into C:\Users\fly165\.conda\pkgs.

How to fix this error?

Change dll_dir to:

#dll_dir = os.path.dirname(__file__) + '\\Qt\\bin'
dll_dir = r'C:\Users\fly165\.conda\pkgs\qt-5.12.5-h7ef1ec2_0\Library\bin'

Run pyqt srouce code, we will find this error is fixed. Here is our pyqt window example.

pyqt simple window example

Leave a Reply

Your email address will not be published. Required fields are marked *