Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"unable to find Qt5Core.dll" that's really there in install folder #4293

Closed
Overdrivr opened this issue Jun 28, 2019 · 25 comments
Closed

"unable to find Qt5Core.dll" that's really there in install folder #4293

Overdrivr opened this issue Jun 28, 2019 · 25 comments

Comments

@Overdrivr
Copy link

Hi folks,

I'm packaging another PyQt5 application, and facing an issue at launch time:

λ XXXXXX.exe
Traceback (most recent call last):
  File "xxxxxx\ui.py", line 4, in <module>
  File "c:\users\remib\.virtualenvs\xxxxxxx-w7udp1ct\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  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
[12876] Failed to execute script ui

What's weird is that the PyQt5 DLL ARE in the install folder, see below:

λ ls
_bz2.pyd*                                                             libdet.ZMMHAPOTSW6C62DXKNECJFSM7BHOWHUN.gfortran-win_amd64.dll*       pythoncom36.dll*
_ctypes.pyd*                                                          libdfft_sub.KKMBYGLUBRBUGJQFW5JJVAPTCGSANMXI.gfortran-win_amd64.dll*  pywintypes36.dll*
_decimal.pyd*                                                         libdfitpack.KTCF3EOE66VRDKN45KBQA4VBAIS552IF.gfortran-win_amd64.dll*  pywt/
_elementtree.pyd*                                                     libdgamln.KEPNNGOAGQPEAK4EIZF7LKL6V6J3KVTB.gfortran-win_amd64.dll*    Qt5Core.dll*
_hashlib.pyd*                                                         libdop853.6TJTQZW3I3Q3QIDQHEOBEZKJ3NYRXI4B.gfortran-win_amd64.dll*    Qt5DBus.dll*
_lzma.pyd*                                                            libdqag.JPQXXMFABPSUCWZNWIAYLRCSU7LERJA3.gfortran-win_amd64.dll*      Qt5Gui.dll*
_multiprocessing.pyd*                                                 libgetbreak.HTWLRMFFYU6U4P3OELXEUG2TRLC63Q6O.gfortran-win_amd64.dll*  Qt5Network.dll*
_socket.pyd*                                                          libGLESv2.dll*                                                        Qt5Qml.dll*
_ssl.pyd*                                                             liblbfgsb.STIIZCVNQ3EDALPZSBDMQ4N77VAEOROT.gfortran-win_amd64.dll*    Qt5Quick.dll*
_tkinter.pyd*                                                         libmvndst.ESZZP47EV6RKCFYTPDCSXD6LWVEBJFUI.gfortran-win_amd64.dll*    Qt5Svg.dll*
_win32sysloader.pyd*                                                  libnnls.IXEEHJUCGHJL42YZEM6UIEMROJWXHMLJ.gfortran-win_amd64.dll*      Qt5WebSockets.dll*
base_library.zip                                                      libopenblas.TXA6YQSD3GCQQC22GEQ54J2UDCXDXHWN.gfortran-win_amd64.dll*  Qt5Widgets.dll*
certifi/                                                              libslsqp_op.LIFGE6AEK5GZMIV4YAH6Q4UEDG4INU5S.gfortran-win_amd64.dll*  scipy/
imageio/                                                              libspecfun.BHLTWMBI4EYWDACZN4DQUESSDJRJNGEL.gfortran-win_amd64.dll*   select.pyd*
Include/                                                              libvode.CIWG4DXTZLMLLSUOOTCVDGAHHMGB4MSJ.gfortran-win_amd64.dll*      skimage/
kiwisolver.cp36-win_amd64.pyd*                                        libwrap_dum.PUJB2YVEA3MDDOZCJDFTG7NSA7QDNOGQ.gfortran-win_amd64.dll*  tcl/
lib_arpack-.6ZMFEI7AX43F2WSEWXPK5DU7RBANYO6W.gfortran-win_amd64.dll*  libwrap_dum.QZ5FOP7XPBZUSV5YTOAYY5YCYRRMXYJR.gfortran-win_amd64.dll*  tcl86t.dll*
lib_blas_su.CEZS2K36QVCBWZVJTBEP5WLPIXAZCNXI.gfortran-win_amd64.dll*  matplotlib/                                                           tk/
lib_test_fo.JF5HTWMUPBXWGAYEBVEJU3OZAHTSVKCT.gfortran-win_amd64.dll*  mfc140u.dll*                                                          tk86t.dll*
libansari.R6EA3HQP5KZ6TAXU4Y4ZVTRPT7UVA53Z.gfortran-win_amd64.dll*    mpl-data/                                                             unicodedata.pyd*
libbanded5x.MJRQXT345OUNLSEQCNZUJHICPOV3UKUD.gfortran-win_amd64.dll*  msvcp140.dll*                                                         VCRUNTIME140.dll*
libbispeu.5N2XSD7URZS4WTOSLTOG4DDMA4HGB46U.gfortran-win_amd64.dll*    XXXXX2.exe*                                                         win32api.pyd*
libblkdta00.D3GJ6OJJJQVX6DSR32FYOAQBLF4LSYXI.gfortran-win_amd64.dll*  XXXXXX2.exe.manifest                                                 win32com/
libchkder.G7WSOGIYYQO3UWFVEZ3PPXCXR53ADVPA.gfortran-win_amd64.dll*    numpy/                                                                win32pdh.pyd*
libcobyla2.JEGTSUUFJ7DFXWZN5PAYZTTLBDATC4WD.gfortran-win_amd64.dll*   PIL/                                                                  win32trace.pyd*
libd_odr.X7OYNKQGMJEKOLBE332F2FJ4TSIT7JWP.gfortran-win_amd64.dll*     pyexpat.pyd*                                                          win32ui.pyd*
libdcosqb.BFJ36UD5XZWZE5UMOTP5UDYKAJ3LWZ6R.gfortran-win_amd64.dll*    PyQt5/                                                                win32wnet.pyd*
libdcosqb.YMN7XEXYADIEZSKAGEVNR4E3MD7AXDG2.gfortran-win_amd64.dll*    python3.dll*
libdcsrch.I2AOPDCXAPDRFNPWY55H5UE7XZSU5CVN.gfortran-win_amd64.dll*    python36.dll*

I thought that the base directory of the EXE file would at least be in the PATH, yet pyinstaller's bootloader can't find this DLL. Any idea on how to debug this ?

I'm puzzled because I recently packaged a similar PyQt5 app without problem.

@Overdrivr
Copy link
Author

Overdrivr commented Jun 28, 2019

Ok so I found the origin of the issue and a workaround.
The issue is there with PyQt5 5.12.3, but not 5.12.1. Haven't tested 5.12.2.
It looks like they've made some modifications to find_qt in between those versions.

Moving manually the PyQt5Core.dll file into PyQt5/qt/bin folder seems to solve the issue, so maybe we could update the hook to reflect that ?

@KmolYuan
Copy link

KmolYuan commented Jun 29, 2019

@Overdrivr PyQt 5.12.2 has been tested without problems. My CI links: 5.12.2 / 5.12.3.

@Overdrivr
Copy link
Author

That's not correct, CI build for 5.12.3 crashes with exactly this error.

@KmolYuan
Copy link

@Overdrivr Sure, I actually mean that.

@Overdrivr
Copy link
Author

Ah yes sorry, misread your message. Ok so we know where to look around for changes.

@MohitMourya
Copy link

MohitMourya commented Jul 1, 2019

Hey! I'm getting this exact error too. I tried adding PyQt5/Qt/bin path, tried adding Qt5core.dll to added data and added binary also in pyinstaller. But still same error
PS: PyQt5/qt/bin path already contains all .DLLs
here's my .spec file

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['MainWindow.py'],
             pathex=['C:\\Users\\ASUS\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\site-packages\\PyQt5\\Qt\\bin', 'D:\\GUI'],
             binaries=[('C:\\Users\\ASUS\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\site-packages\\PyQt5\\Qt\\bin\\Qt5Core.dll', '.')],
             datas=[('C:\\Users\\ASUS\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\site-packages\\PyQt5\\Qt\\bin\\Qt5Core.dll', '.')],
             hiddenimports=['PyQt5','PyQt5.QtNetwork','PyQt5.QtMultimedia','PyQt5.QtCore','PyQt5.QtGui','PyQt5.QtWidgets','cv2'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='App',
          debug=True,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )

@KmolYuan
Copy link

KmolYuan commented Jul 1, 2019

Here is the new function find_qt in version 5.12.3:

def find_qt():
    import os

    path = os.environ['PATH']

    dll_dir = os.path.dirname(__file__) + '\\Qt\\bin'
    if os.path.isfile(dll_dir + '\\Qt5Core.dll'):
        path = dll_dir + ';' + path
        os.environ['PATH'] = path
    else:
        for dll_dir in path.split(';'):
            if os.path.isfile(dll_dir + '\\Qt5Core.dll'):
                break
        else:
            raise ImportError("unable to find Qt5Core.dll on PATH")

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


find_qt()
del find_qt

Where the nonexistence of Qt5Core.dll will proactively raise errors now.

The previous version:

import os as _os

_path = _os.path.dirname(__file__) + '\\Qt\\bin;' + _os.environ['PATH']
_os.environ['PATH'] = _path

In "manylinux" or "macosx", the file PyQt5/__init__.py is empty.

@KmolYuan
Copy link

KmolYuan commented Jul 1, 2019

My PyQt objects import uniformly in a file (QtModules.py).

Update environment variable PATH before start using PyQt objects:

# QtModules.py
import os
import sys
if hasattr(sys, 'frozen'):
    os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH']
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtChart import *
...

It's strange that Qt5*.dll are 5.12.4 but the packed version is 5.12.3. After I replaced them with 5.12.4, it works again!

My program log about environment:

OS Type: Windows 10 [AMD64]
Python Version: 3.7.0(final)
Python Compiler: MSC v.1914 64 bit (AMD64)
Qt Version: 5.12.4
PyQt Version: 5.12.3

Needs to:

  1. Add sys._MEIPASS path into os.environ['PATH'] before import PyQt.
  2. DLL's version are not match PYD's.

EchterAgo added a commit to EchterAgo/Electron-Cash that referenced this issue Jul 3, 2019
This allows us to properly use color emojis on Linux and we don't need to
add libQt5MultimediaGstTools anymore.

We include a workaround to make PyQt5 5.12.3 work with PyInstaller,
otherwise it would fail to start saying it can't find QtCore.dll.

See pyinstaller/pyinstaller#4293

We also remove an unneeded copy of the Qt binaries.
EchterAgo added a commit to EchterAgo/Electron-Cash that referenced this issue Jul 3, 2019
This allows us to properly use color emojis on Linux and we don't need to
add libQt5MultimediaGstTools anymore.

We include a workaround to make PyQt5 5.12.3 work with PyInstaller,
otherwise it would fail to start saying it can't find QtCore.dll.

See pyinstaller/pyinstaller#4293

We also remove an unneeded copy of the Qt binaries.
cculianu pushed a commit to simpleledger/Electron-Cash-SLP that referenced this issue Jul 3, 2019
This allows us to properly use color emojis on Linux and we don't need to
add libQt5MultimediaGstTools anymore.

We include a workaround to make PyQt5 5.12.3 work with PyInstaller,
otherwise it would fail to start saying it can't find QtCore.dll.

See pyinstaller/pyinstaller#4293

We also remove an unneeded copy of the Qt binaries.
@Ronkiro
Copy link

Ronkiro commented Jul 10, 2019

Found same issue for PyQt 5.13.0 (via pip)

(Downgrading to 5.12.2 also fixed the problem)

@akai-katto
Copy link

Found same issue for PyQt 5.13.0 (via pip)

(Downgrading to 5.12.2 also fixed the problem)

Can confirm this worked for me also

@StephaineWYT
Copy link

Ok so I found the origin of the issue and a workaround.
The issue is there with PyQt5 5.12.3, but not 5.12.1. Haven't tested 5.12.2.
It looks like they've made some modifications to find_qt in between those versions.

Moving manually the PyQt5Core.dll file into PyQt5/qt/bin folder seems to solve the issue, so maybe we could update the hook to reflect that ?

Thank u sooooo much, ur point really help me out

@matthewgdv
Copy link

Would anyone be willing to fix this for PyQt5 5.12.3? It's a bit annoying to have to use the manual workaround described above for every single deploy.

@KmolYuan
Copy link

@matthewgdv I don't know much about PyInstaller, just some ideas.

The first step of modifying os.environ['PATH'] might be here?
https://github.com/pyinstaller/pyinstaller/blob/master/PyInstaller/loader/rthooks/pyi_rth_pyqt5.py

os.environ['PATH'] = sys._MEIPASS + os.pathsep + os.environ['PATH']

And does anyone know where the copy functions of Qt5*.dll are?
They matched wrong version as original PyQt (Should be from PyQt5\Qt\bin).

@Ronkiro
Copy link

Ronkiro commented Jul 24, 2019

Would anyone be willing to fix this for PyQt5 5.12.3? It's a bit annoying to have to use the manual workaround described above for every single deploy.

If fixed, this will probably given in a new release i think. As this isn't version specific, as i said, 5.13.0 is also affected. I think all > 5.12.2 are.

@KmolYuan
Copy link

KmolYuan commented Jul 25, 2019

After applied the patch of pyi_rth_pyqt5.py, PyInstaller works fine for PyQt 5.13.0 (Qt 5.13.0). #4332

I will test the version of PyQt 5.12.3 (Qt 5.12.4).


Update:

It seems that the Qt5*.dll version error has been solved in PyInstaller 3.5.

Can you help me test if this patch is a generic solution?

@Duskhorizon
Copy link

After applied the patch of pyi_rth_pyqt5.py, PyInstaller works fine for PyQt 5.13.0 (Qt 5.13.0). #4332

I will test the version of PyQt 5.12.3 (Qt 5.12.4).

Update:

It seems that the Qt5*.dll version error has been solved in PyInstaller 3.5.

Can you help me test if this patch is a generic solution?

Still, have problem with or without patch

@KmolYuan
Copy link

@Duskhorizon What is the error message?

@snaphat
Copy link

snaphat commented Jul 30, 2019

@Duskhorizon What is the error message?

Doesn't work for me either

c:\python37\lib\site-packages\pyinstaller-4.0.dev0+g83eaed59.mod-py3.7.egg\PyInstaller\loader\pyimod03_importers.py:621: MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3.
  exec(bytecode, module.__dict__)
Traceback (most recent call last):
  File "nud_analyzing_toolkit.py", line 18, in <module>
    import PyQt5.QtCore
  File "c:\python37\lib\site-packages\pyinstaller-4.0.dev0+g83eaed59.mod-py3.7.egg\PyInstaller\loader\pyimod03_importers.py", line 621, in exec_module
    exec(bytecode, module.__dict__)
  File "PyQt5\__init__.py", line 41, in <module>
  File "PyQt5\__init__.py", line 33, in find_qt
ImportError: unable to find Qt5Core.dll on PATH

@snaphat
Copy link

snaphat commented Jul 30, 2019

Manually added the following to my spec file and it works after that.

...
datas=[(HOMEPATH + '\\..\\PyQt5\\Qt\\bin\*', 'PyQt5\\Qt\\bin')],
...

Note this needs to be modified to the following for regular pyinstaller (non-developmental build):

...
datas=[(HOMEPATH + '\\PyQt5\\Qt\\bin\*', 'PyQt5\\Qt\\bin')],
...

@sherylwithans
Copy link

sherylwithans commented Jul 30, 2019

Manually added the following to my spec file and it works after that.

...
datas=[(HOMEPATH + '\\..\\PyQt5\\Qt\\bin\*', 'PyQt5\\Qt\\bin')],
...

Note this needs to be modified to the following for regular pyinstaller (non-developmental build):

...
datas=[(HOMEPATH + '\\PyQt5\\Qt\\bin\*', 'PyQt5\\Qt\\bin')],
...

This worked perfectly, thank you so so much!
For those interested, the command line code would be:

--add-data site-packages\\PyQt5\\Qt\\bin;PyQt5\\Qt\\bin

(Address adjusted based on where PyQt5 ins installed)

@vstupakov
Copy link

@sz2723 Thanks! It works for me.

I've wrote it in this way for my project:

from pathlib import Path
import os
import PyQt5

opts = [ ...
    f"--add-data={Path(PyQt5.__file__).parent}/Qt/bin{os.pathsep}PyQt5/Qt/bin"
]

@bjones1
Copy link
Contributor

bjones1 commented Aug 2, 2019

This is fixed now as of 47bd7f1.

@djotaku
Copy link

djotaku commented Sep 24, 2019

Hello,

I'm getting exactly the same error as:
ImportError: unable to find Qt5Core.dll on PATH

Just installed via PIP today on Windows.

@umar13893
Copy link

umar13893 commented Oct 2, 2019

I upgraded my PyQt5 to 5.13.1 and it's fixed.

e.g pip install PyQt5 -- upgrade

@danishyasin33
Copy link

ds to be modified to the following for regular pyinst

This worked after excruciating debugging.

cbm755 added a commit to plomgrading/plom that referenced this issue Sep 4, 2021
At least I hope so...  When I bumped PyQt5 to 5.15.4 I got this:
```
15839 INFO: Appending 'datas' from .spec
Unable to find "c:\python39\lib\site-packages\PyQt5\Qt\bin\*" when adding binary and data files.
```
The code I'm removing here it is from:
pyinstaller/pyinstaller#4293 (comment)

PyQt5 python packaging changed a lot between 5.15.2 and 5.15.3.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests