How To Fix "importerror: Unable To Find Qt5core.dll On Path" After Pyinstaller Bundled The Python Application
Solution 1:
As detailed in the question, when startup the bundled application in the conda console, it runs properly, all the loaded DLLs, exported by ProcessExplorer
, are in the dist dir which was created by pyinstaller. So the problem is that the path, containing pyqt DLLs, is not in the system's PATH
environment. Maybe this is a bug of pyinstaller. The Solution is add the program path to system PATH
env manually.
Here is the code snip i am using:
# Fix qt import error# Include this file before import PyQt5 import os
import sys
import logging
def_append_run_path():
ifgetattr(sys, 'frozen', False):
pathlist = []
# If the application is run as a bundle, the pyInstaller bootloader# extends the sys module by a flag frozen=True and sets the app# path into variable _MEIPASS'.
pathlist.append(sys._MEIPASS)
# the application exe path
_main_app_path = os.path.dirname(sys.executable)
pathlist.append(_main_app_path)
# append to system path enviroment
os.environ["PATH"] += os.pathsep + os.pathsep.join(pathlist)
logging.error("current PATH: %s", os.environ['PATH'])
_append_run_path()
Solution 2:
Assuming you don't absolutely need PyQt5 version 5.13.0, the easiest fix is to simply downgrade PyQt5 to version 5.12.2 using:
pip install pyqt5==5.12.2
and your executable will work as expected.
Solution 3:
Ran into the same issue after upgrade to Qt5.13. Found this solution on pyinstaller github You need to modify the .spec file and put the following:
datas=[(HOMEPATH + '\\PyQt5\\Qt\\bin\*', 'PyQt5\\Qt\\bin')],
Solution 4:
I comment all content of file site-packages\PyQt5\__init__.py
and install again. It works.
I use python3.5
with PyInstaller=3.5
and PyQt5=5.13.0
.The packaged exe is working on my computer, but does not work on others. The error message is:
File "anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
File "site-packages\PyQt5\__init__.py", line 41, in <module>
File "site-packages\PyQt5\__init__.py", line 33, in find_qt
ImportError: unable to find Qt5Core.dll on PATH
So I see site-packages\PyQt5\__init__.py
(5.13.0) is:
def find_qt():
import ospath = os.environ['PATH']
dll_dir = os.path.dirname(__file__) + '\\Qt\\bin'ifos.path.isfile(dll_dir + '\\Qt5Core.dll'):
path = dll_dir + ';' + pathos.environ['PATH'] = pathelse:
for dll_dir inpath.split(';'):
ifos.path.isfile(dll_dir + '\\Qt5Core.dll'):
breakelse:
raise ImportError("unable to find Qt5Core.dll on PATH")
try:
os.add_dll_directory(dll_dir)
except AttributeError:
pass
find_qt()
del find_qt
I think PyQt5 can't find the PATH in the other computer although Qt5Core.dll
already exists in the
project directly. So I commented out the file and now it works.
Solution 5:
I solved this for myself by commenting all in site-packages\PyQt5\__init__.py
and adding this code from an older version of QT __init__.py
:
import os as _os_path= _os.path.dirname(__file__) + '\\Qt\\bin;' + _os.environ['PATH']
_os.environ['PATH'] = _path
Post a Comment for "How To Fix "importerror: Unable To Find Qt5core.dll On Path" After Pyinstaller Bundled The Python Application"