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

minimalistic PyQt 5.6.0 project "could not find or load the Qt platform plugin "windows"" #2857

Closed
user-na opened this Issue Sep 23, 2017 · 67 comments

Comments

Projects
None yet
@user-na

user-na commented Sep 23, 2017

latest Anaconda 2 64bit (4.4.0)
python 2.7.13
PyQt 5.6.0
pyinstaller 3.4.dev0+g162fe92d

When I try to freeze this minimalized example with pyinstaller:

from PyQt5 import QtWidgets
import sys
if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    print 'app loaded'

The resulting executable is throwing

This application failed to start because it could not find or load the Qt platform plugin "windows"
in "".

In the DIST Folder PyInstaller is in fact providing the Qt dlls:

...\DIST\minimalized\PYQT5
└───Qt
    └───plugins
        ├───iconengines
        │       qsvgicon.dll
        │
        ├───imageformats
        │       qdds.dll
        │       qgif.dll
        │       qicns.dll
        │       qico.dll
        │       qjpeg.dll
        │       qsvg.dll
        │       qtga.dll
        │       qtiff.dll
        │       qwbmp.dll
        │       qwebp.dll
        │
        ├───platforms
        │       qminimal.dll
        │       qoffscreen.dll
        │       qwindows.dll
        │
        └───printsupport
                windowsprintersupport.dll

As far as I can tell, Qt is looking for the libaries at some default paths, rather than in the provided directory. When I add anacondas qt.conf (located at C:\ProgramData\Anaconda2) in the spec file as external file the program is running correctly. The content of the spec file is

[Paths]
Prefix = C:/ProgramData/Anaconda2/Library
Binaries = C:/ProgramData/Anaconda2/Library/bin
Libraries = C:/ProgramData/Anaconda2/Library/lib
Headers = C:/ProgramData/Anaconda2/Library/include/qt

As this file is system specific the resulting exe is not really stand alone. As there is no 1:1 mapping from the present PyQt5 path to the folders in the...\Libary\ path how does a system independend qt.conf file look like? And shouldn't the hook file for PyQt create the qt.conf automatically?
Thanks for your support!

@user-na user-na changed the title from pyinstaller fails to create minimalistic PyQt 5.6.0 project to minimalistic PyQt 5.6.0 project "could not find or load the Qt platform plugin "windows"" Sep 23, 2017

@carlosperate

This comment has been minimized.

carlosperate commented Sep 24, 2017

Related: #2301 #1688
Did you try with UPX deactivated?

@user-na

This comment has been minimized.

user-na commented Sep 24, 2017

Oh, thanks for the hint, I will try to deactivate UPX.
Maybe I add some additional stuff which I figured out in the meantime,
Actually the build is comming will all what the executable needs to run.
The isssue it that the default QT path for Prefix is pointing to QCoreApplication::applicationDirPath() which in our case is the path of the executable. The problem is now, that the hirachy of the QT folder is to deep, so that the executable will not discover the libaries. This can be fixed by either copying the content of ./PyQt5/Qt/plugins to ./ (copying the content of ./PyQt5/Qt or ./PyQt5/ does not work by the way...) or by adding a qt.conf file to ./ containing the following lines.

[Paths]
Prefix = PyQt5/Qt

So it seems that when using a qt.conf file it will crawl deeper through the provided folder than for the default case
I will now try to disable UPX and then post my results.

@carlosperate

This comment has been minimized.

carlosperate commented Sep 24, 2017

Thanks for the additional info @user-na. I'll look into changing the dlls location as well.

For further information, I am experiencing the same issue on builds created in AppVeyor.

Windows Server 2012 R2
Python 3.4.4
PyQt5-5.5.1
PyInstaller 3.3

With the UPX flag set to False in the spec file.

@user-na

This comment has been minimized.

user-na commented Sep 24, 2017

Running pyinstaller with --noupx does not change the behavior for this issue.

@user-na

This comment has been minimized.

user-na commented Sep 25, 2017

Trying the same thing at a vanilla python 3 installation actually does not reproduce the issue. Here pyinstaller is creating the following structure:

...PYQT5
└───Qt
    ├───bin
    │       qt.conf
    │
    └───plugins
        ├───iconengines
        │       qsvgicon.dll
        │
        ├───imageformats
        │       qgif.dll
        │       qicns.dll
        │       qico.dll
        │       qjpeg.dll
        │       qsvg.dll
        │       qtga.dll
        │       qtiff.dll
        │       qwbmp.dll
        │       qwebp.dll
        │
        ├───platforms
        │       qminimal.dll
        │       qoffscreen.dll
        │       qwindows.dll
        │
        └───printsupport
                windowsprintersupport.dll

As you see in this configuration pyinstaller creates a qt.conf file in the Qt\bin folder. The content of this file is

[Paths]
Prefix = ..

So it is basically pointing to PyQt5/Qt which is the same as I did in my manually created conf file....

@carlosperate

This comment has been minimized.

carlosperate commented Sep 25, 2017

I'm having this problem with Python 3 on Windows and I'm not quite seeing the same results (I don't get any qt.conf, and when manually added one as shown in a previous message, it didn't make a difference):

Windows Server 2012 R2
Python 3.4.4
PyQt5-5.5.1
PyInstaller 3.3

Example script: https://github.com/carlosperate/pyqtconsole-test/blob/754d7892ca1282b2e70c6a579fa762a3928ef51f/pyqt5_test.py

import sys
from PyQt5.QtWidgets import QApplication, QWidget

if __name__ == '__main__':
    app = QApplication(sys.argv)
    example = QWidget()
    example.setGeometry(100, 100, 640, 480)
    example.show()
    print('App loaded')
    sys.exit(app.exec_())

Spec file (one file, no upx): https://github.com/carlosperate/pyqtconsole-test/blob/754d7892ca1282b2e70c6a579fa762a3928ef51f/package/pyqt5_test.spec

AppVeyor log: https://ci.appveyor.com/project/carlosperate/pyqtconsole-test/build/1.0.7#L182

Output file: https://s3-eu-west-2.amazonaws.com/mu-builds/pyinstaller/pyqt5_test2017-09-25_11_08_master_754d789.exe

Upacked temporary folder directory tree:

│   base_library.zip
│   icudt53.dll
│   icuin53.dll
│   icuuc53.dll
│   MSVCP100.dll
│   MSVCR100.dll
│   pyexpat.pyd
│   PyQt5.Qt.pyd
│   PyQt5.QtCore.pyd
│   PyQt5.QtGui.pyd
│   PyQt5.QtPrintSupport.pyd
│   PyQt5.QtWidgets.pyd
│   pyqt5_test.exe.manifest
│   python34.dll
│   Qt5Core.dll
│   Qt5Gui.dll
│   Qt5PrintSupport.dll
│   Qt5Svg.dll
│   Qt5Widgets.dll
│   select.pyd
│   sip.pyd
│   unicodedata.pyd
│   _bz2.pyd
│   _ctypes.pyd
│   _hashlib.pyd
│   _lzma.pyd
│   _socket.pyd
│   _ssl.pyd
│
├───Include
│       pyconfig.h
│
└───PyQt5
    └───Qt
        └───plugins
            ├───iconengines
            │       qsvgicon.dll
            │
            ├───imageformats
            │       qdds.dll
            │       qgif.dll
            │       qicns.dll
            │       qico.dll
            │       qjp2.dll
            │       qjpeg.dll
            │       qmng.dll
            │       qsvg.dll
            │       qtga.dll
            │       qtiff.dll
            │       qwbmp.dll
            │       qwebp.dll
            │
            ├───platforms
            │       qminimal.dll
            │       qoffscreen.dll
            │       qwindows.dll
            │
            └───printsupport
                    windowsprintersupport.dll

Build output:

pyinstaller package\pyqt5_test.spec
78 INFO: PyInstaller: 3.3
78 INFO: Python: 3.4.4
78 INFO: Platform: Windows-2012ServerR2-6.3.9600
93 INFO: UPX is not available.
93 INFO: Extending PYTHONPATH with paths
['C:\\projects\\pyqtconsole-test',
 'C:\\projects',
 'c:\\python34\\lib\\site-packages\\PyQt5',
 'c:\\python34\\lib\\site-packages\\PyQt5\\plugins\\platforms']
93 INFO: checking Analysis
93 INFO: Building Analysis because out00-Analysis.toc is non existent
93 INFO: Initializing module dependency graph...
93 INFO: Initializing module graph hooks...
93 INFO: Analyzing base_library.zip ...
2437 INFO: Processing pre-find module path hook   distutils
4249 INFO: running Analysis out00-Analysis.toc
4656 INFO: Caching module hooks...
4671 INFO: Analyzing pyqt5_test.py
4687 INFO: Loading module hooks...
4687 INFO: Loading module hook "hook-distutils.py"...
4687 INFO: Loading module hook "hook-encodings.py"...
4765 INFO: Loading module hook "hook-PyQt5.py"...
4765 INFO: Loading module hook "hook-xml.py"...
5093 INFO: Loading module hook "hook-pydoc.py"...
5093 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
5093 INFO: Loading module hook "hook-PyQt5.Qt.py"...
5093 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
5187 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
5515 INFO: Loading module hook "hook-PyQt5.QtPrintSupport.py"...
5578 INFO: Looking for ctypes DLLs
5593 INFO: Analyzing run-time hooks ...
5609 INFO: Including run-time hook 'pyi_rth_qt5.py'
5609 INFO: Looking for dynamic libraries
6421 INFO: Looking for eggs
6421 INFO: Using Python library C:\windows\system32\python34.dll
6421 INFO: Found binding redirects: 
[]
6437 INFO: Warnings written to C:\projects\pyqtconsole-test\build\pyqt5_test\warnpyqt5_test.txt
6484 INFO: Graph cross-reference written to C:\projects\pyqtconsole-test\build\pyqt5_test\xref-pyqt5_test.html
6515 INFO: checking PYZ
6515 INFO: Building PYZ because out00-PYZ.toc is non existent
6515 INFO: Building PYZ (ZlibArchive) C:\projects\pyqtconsole-test\build\pyqt5_test\out00-PYZ.pyz
7484 INFO: Building PYZ (ZlibArchive) C:\projects\pyqtconsole-test\build\pyqt5_test\out00-PYZ.pyz completed successfully.
7499 INFO: checking PKG
7499 INFO: Building PKG because out00-PKG.toc is non existent
7499 INFO: Building PKG (CArchive) out00-PKG.pkg
7515 INFO: Updating manifest in C:\Users\appveyor\AppData\Roaming\pyinstaller\bincache00_py34_32bit\python34.dll
7515 INFO: Updating resource type 24 name 2 language 1033
7671 INFO: Updating manifest in C:\Users\appveyor\AppData\Roaming\pyinstaller\bincache00_py34_32bit\sip.pyd
7671 INFO: Updating resource type 24 name 2 language 1033
7703 INFO: Updating manifest in C:\Users\appveyor\AppData\Roaming\pyinstaller\bincache00_py34_32bit\qt5gui.dll
7703 INFO: Updating resource type 24 name 2 language 1033
7734 INFO: Updating manifest in C:\Users\appveyor\AppData\Roaming\pyinstaller\bincache00_py34_32bit\qt5core.dll
7734 INFO: Updating resource type 24 name 2 language 1033
7749 INFO: Updating manifest in C:\Users\appveyor\AppData\Roaming\pyinstaller\bincache00_py34_32bit\qt5svg.dll
7749 INFO: Updating resource type 24 name 2 language 1033
7749 INFO: Updating manifest in C:\Users\appveyor\AppData\Roaming\pyinstaller\bincache00_py34_32bit\qt5printsupport.dll
7749 INFO: Updating resource type 24 name 2 language 1033
7781 INFO: Updating manifest in C:\Users\appveyor\AppData\Roaming\pyinstaller\bincache00_py34_32bit\qt5widgets.dll
7781 INFO: Updating resource type 24 name 2 language 1033
7796 INFO: Updating manifest in C:\Users\appveyor\AppData\Roaming\pyinstaller\bincache00_py34_32bit\icuuc53.dll
7796 INFO: Updating resource type 24 name 2 language 1033
7812 INFO: Updating manifest in C:\Users\appveyor\AppData\Roaming\pyinstaller\bincache00_py34_32bit\icuin53.dll
7812 INFO: Updating resource type 24 name 2 language 1033
18062 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
18062 INFO: Bootloader c:\python34\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run_d.exe
18062 INFO: checking EXE
18062 INFO: Building EXE because out00-EXE.toc is non existent
18062 INFO: Building EXE from out00-EXE.toc
18062 INFO: Appending archive to EXE C:\projects\pyqtconsole-test\dist\pyqt5_test.exe
18093 INFO: Building EXE from out00-EXE.toc completed successfully.

Console output when executing exe:

[19608] PyInstaller Bootloader 3.x
[19608] LOADER: executable is C:\Users\carlo\Downloads\pyqt5_test2017-09-25_11_08_master_754d789.exe
[19608] LOADER: homepath is C:\Users\carlo\Downloads
[19608] LOADER: _MEIPASS2 is NULL
[19608] LOADER: archivename is C:\Users\carlo\Downloads\pyqt5_test2017-09-25_11_08_master_754d789.exe
[19608] LOADER: Extracting binaries
[19608] LOADER: Executing self as child
[19608] LOADER: set _MEIPASS2 to C:\Users\carlo\AppData\Local\Temp\_MEI196082
[19608] LOADER: Setting up to run child
[19608] LOADER: Creating child process
[19608] LOADER: Waiting for child process to finish...
[18240] PyInstaller Bootloader 3.x
[18240] LOADER: executable is C:\Users\carlo\Downloads\pyqt5_test2017-09-25_11_08_master_754d789.exe
[18240] LOADER: homepath is C:\Users\carlo\Downloads
[18240] LOADER: _MEIPASS2 is C:\Users\carlo\AppData\Local\Temp\_MEI196082
[18240] LOADER: archivename is C:\Users\carlo\Downloads\pyqt5_test2017-09-25_11_08_master_754d789.exe
[18240] LOADER: SetDllDirectory(C:\Users\carlo\AppData\Local\Temp\_MEI196082)
[18240] LOADER: Already in the child - running user's code.
[18240] LOADER: manifestpath: C:\Users\carlo\AppData\Local\Temp\_MEI196082\pyqt5_test.exe.manifest
[18240] LOADER: Activation context created
[18240] LOADER: Activation context activated
[18240] LOADER: Python library: C:\Users\carlo\AppData\Local\Temp\_MEI196082\python34.dll
[18240] LOADER: Loaded functions from Python library.
[18240] LOADER: Manipulating environment (sys.path, sys.prefix)
[18240] LOADER: Pre-init sys.path is C:\Users\carlo\AppData\Local\Temp\_MEI196082\base_library.zip;C:\Users\carlo\AppData\Local\Temp\_MEI196082
[18240] LOADER: sys.prefix is C:\Users\carlo\AppData\Local\Temp\_MEI196082
[18240] LOADER: Setting runtime options
[18240] LOADER: Bootloader option: pyi-windows-manifest-filename pyqt5_test.exe.manifest
[18240] LOADER: Initializing python
[18240] LOADER: Overriding Python's sys.path
[18240] LOADER: Post-init sys.path is C:\Users\carlo\AppData\Local\Temp\_MEI196082\base_library.zip;C:\Users\carlo\AppData\Local\Temp\_MEI196082
[18240] LOADER: Setting sys.argv
[18240] LOADER: setting sys._MEIPASS
[18240] LOADER: importing modules from CArchive
[18240] LOADER: extracted struct
[18240] LOADER: callfunction returned...
[18240] LOADER: extracted pyimod01_os_path
[18240] LOADER: callfunction returned...
[18240] LOADER: extracted pyimod02_archive
[18240] LOADER: callfunction returned...
[18240] LOADER: extracted pyimod03_importers
[18240] LOADER: callfunction returned...
[18240] LOADER: Installing PYZ archive with Python modules.
[18240] LOADER: PYZ archive: out00-PYZ.pyz
[18240] LOADER: Running pyiboot01_bootstrap.py
[18240] LOADER: Running pyi_rth_qt5.py
[18240] LOADER: Running pyqt5_test.py
This application failed to start because it could not find or load the Qt platform plugin "windows".

Reinstalling the application may fix this problem.
[19608] LOADER: Back to parent (RC: 1)
[19608] LOADER: Doing cleanup
[19608] LOADER: Freeing archive status for C:\Users\carlo\Downloads\pyqt5_test2017-09-25_11_08_master_754d789.exe
@ChadSki

This comment has been minimized.

ChadSki commented Sep 25, 2017

@carlosperate try moving \PyQt5\Qt\plugins\platforms\qwindows.dll to \plugins\platforms\qwindows.dll or \platforms\qwindows.dll (one of these worked for me but I forget which).

Not sure why this move operation should be required, but it allows the program to run.

@carlosperate

This comment has been minimized.

carlosperate commented Sep 26, 2017

Thanks @ChadSki, I've added extra copies of the dlls to a platforms and plugins\platforms folder, but I still get the same issue.

Copied of the dlls added as binary files in the spec file: carlosperate/pyinstaller-test@0180532

AppVeyor output: https://ci.appveyor.com/project/carlosperate/pyqtconsole-test/build/1.0.9

Exe output: https://s3-eu-west-2.amazonaws.com/mu-builds/pyinstaller/pyqt5_test2017-09-26_00_26_copy_dlls_0180532.exe

The unpacked temporary folder directory tree now also contains these two extra folders:

...
│   _ssl.pyd
│
├───Include
│       pyconfig.h
│
├───platforms
│       qminimal.dll
│       qoffscreen.dll
│       qwindows.dll
│
├───plugins
│   └───platforms
│           qminimal.dll
│           qoffscreen.dll
│           qwindows.dll
│
└───PyQt5
    └───Qt
        |
...

And still seeing:

[12632] LOADER: Running pyqt5_test.py
This application failed to start because it could not find or load the Qt platform plugin "windows".

Not really sure how identify what dlls might be missing, is there any way to debug or get more info to help this process?

@carlosperate

This comment has been minimized.

carlosperate commented Sep 26, 2017

Also, having a PyQt5/Qt/bin/qt.conf with (carlosperate/pyinstaller-test@cb72f35):

[Paths]
Prefix = ..

Or a ./qt.conf file with (carlosperate/pyinstaller-test@a37292d):

[Paths]
Prefix = PyQt5/Qt

Did not solve the issue either.

@ChadSki

This comment has been minimized.

ChadSki commented Sep 26, 2017

Ah you're right, that's not sufficient to fix the issue. I also added this code to my project:

if getattr(sys, 'frozen', False):
    # running in a bundle, do path muckery
    print(sys.path)
    here = os.path.dirname(sys.executable)
    sys.path.insert(1, here)
    print(sys.path)
@shadchin

This comment has been minimized.

shadchin commented Sep 27, 2017

I have the same issue, if there are non-ascii chars in path (example, d:\ФФ\project)

@carlosperate

This comment has been minimized.

carlosperate commented Sep 28, 2017

Thanks for the follow up and additional info @ChadSki!

I assume the purpose of the code you added to your comment is to add the directory with all the uncompressed files into the sys.path. I think this is something that should happen automatically by PyInstaller, or at least it does in my current environment (in my case the ...\AppData\Local\Temp\_MEIxxxxx folder).

I updated my PyQt test script to print additional info before it crashes (full file):

print("Python sys.executable:\n\t%s" % sys.executable)
print("Python sys.path:\n\t%s" % "\n\t".join(sys.path))
print('Qt5 Libraries path:\n\t%s' % \
        QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.LibrariesPath))
print('Qt5 Library Executables path:\n\t%s' % \
        QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.LibraryExecutablesPath))
print('Qt5 Binaries path:\n\t%s' % \
        QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.BinariesPath))
print('Qt5 Data path:\n\t%s' % \
        QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.DataPath))
print('Qt5 Imports path:\n\t%s' % \
        QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.ImportsPath))
print('Qt5 Plugins path:\n\t%s' % \
        QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.PluginsPath))
print('Qt5 Settings path:\n\t%s' % \
        QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.SettingsPath))
print('Qt5 Prefix path:\n\t%s' % \
        QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.PrefixPath))
print("Qt5 image read support:\n\t%s" % ', '.join([str(format).lower() \
    for format in QtGui.QImageReader.supportedImageFormats()]))

app = QtWidgets.QApplication(sys.argv)

Which printed:

[6444] LOADER: Running pyqt5_test.py
Python sys.executable:
        C:\Users\carlo\Downloads\pyqt5_test2017-09-28_17_43_master_b1512a8.exe
Python sys.path:
        C:\Users\carlo\AppData\Local\Temp\_MEI81562\base_library.zip
        C:\Users\carlo\AppData\Local\Temp\_MEI81562
Qt5 Libraries path:
        C:/Qt/5.5.1/lib
Qt5 Library Executables path:
        C:/Qt/5.5.1/bin
Qt5 Binaries path:
        C:/Qt/5.5.1/bin
Qt5 Data path:
        C:/Qt/5.5.1
Qt5 Imports path:
        C:/Qt/5.5.1/imports
Qt5 Plugins path:
        C:/Qt/5.5.1/plugins
Qt5 Settings path:

Qt5 Prefix path:
        C:/Qt/5.5.1
Qt5 image read support:
        b'bmp', b'pbm', b'pgm', b'png', b'ppm', b'xbm', b'xpm'
This application failed to start because it could not find or load the Qt platform plugin "windows".

Reinstalling the application may fix this problem.

I'm not sure if those paths should still point to the original installation paths ( C:/Qt/5.5.1/...) instead of the bundled folders (C:\Users\carlo\AppData\Local\Temp\_MEI81562\PyQt5\Qt).

@carlosperate

This comment has been minimized.

carlosperate commented Sep 29, 2017

So I tried building on my PC with Python 3.5 and PyQt 5.7 (my reports above are from building in AppVeyor with Python 3.4 and PyQT 5.5) and it yields different path values for the QtCore.QLibraryInfo.<xxxx>Path variables.

While the AppVeyor bundled application points to the original location from the PyQT installation directory (C:/Qt/5.5.1/), my local test points to the unpacked directory created in the user temporary folder
(C:/Users/carlo/AppData/Local/Temp/_MEI96842/PyQt5) (full output here), where these dlls are actually located.

It makes sense that the reason my appveyor builds don't work is because it's looking for the dlls in the wrong directory.

Any help or direction on how to solve this would be greatly appreciated, and I'd be more than happy to provide a PR if this is something that can be included in a hook, but I would need a bit of assistance figuring out how to fix this issue.

@shadchin

This comment has been minimized.

shadchin commented Oct 3, 2017

git bisect says, that break after commit is 675d66a

@shadchin

This comment has been minimized.

shadchin commented Oct 3, 2017

I make 2 fix 082078e and 59a2330. That solved my issue.

@dickreuter

This comment has been minimized.

Contributor

dickreuter commented Oct 15, 2017

I tried that but it doesn't fix the problem for me but updating my venv to pyqt5.9 solved the problem.

@carlosperate

This comment has been minimized.

carlosperate commented Oct 30, 2017

Thank you so much @shadchin! I can confirm you fix works for me with Python 3.4.4 and PyQt5-5.5.1.
Any chance you could submit a PR?

@lneuhaus

This comment has been minimized.

Contributor

lneuhaus commented Nov 7, 2017

@shadchin +1 for the pull request. Thanks a million!

@shadchin

This comment has been minimized.

shadchin commented Nov 12, 2017

Sorry for delay, I submit PR #2991

@carlosperate

This comment has been minimized.

carlosperate commented Nov 12, 2017

Thanks @shadchin !

@pythonengineer

This comment has been minimized.

pythonengineer commented Nov 24, 2017

Yeah, this is still a problem and even when trying the pull request it doesn't fix the problem.

@carlosperate

This comment has been minimized.

carlosperate commented Nov 24, 2017

@pythonengineer continuing the conversation from #2991 here as it's a better place for that.

This is my current error:

This application failed to start because it could not find or load the Qt pl
rm plugin "windows"
in "C:\Users\jsmith\AppData\Local\Temp_MEI40122\qt5_plugins\platforms".

Reinstalling the application may fix this problem.

Which is a strange error, because I was able to access that temp folder while it existed and qwindows.dll was literally right there in the platforms folder.

I think the issue that had before that patch is that while the dll was possibly bundled (definitely at one point, as during my tests I was also manually editing the spec file to catch it and add it), it wasn't placed in the expected directory. Check where those dlls are within the PyQt5 python package directory, and then try to mirror the same folder structure in your bundled app, maybe that helps.

@pythonengineer

This comment has been minimized.

pythonengineer commented Nov 25, 2017

@carlosperate PyInstaller is actually successfully placing qwindows.dll in the executable, it's just that for some reason the program isn't 'seeing' the DLL even though the path is correct. The path in the error had qwindows.dll, but it says it couldn't find it somehow even though it was looking in the folder that had it. But it also said "could not find or LOAD", so could PyInstaller be corrupting the dll??

@carlosperate

This comment has been minimized.

carlosperate commented Nov 25, 2017

Related: #2301 #1688
If you are using UPX, try disabling it.

@pythonengineer

This comment has been minimized.

pythonengineer commented Nov 25, 2017

@carlosperate I haven't been using UPX. I just don't understand, it's trying to load from the right path, but it can't find/load it?

@bjones1

This comment has been minimized.

Member

bjones1 commented Jan 31, 2018

I'm closing this, since #3233 should fix it -- see the instructions there.

@bjones1 bjones1 closed this Jan 31, 2018

@DCMMC

This comment has been minimized.

DCMMC commented Feb 24, 2018

Thank you soooo much @shadchin ! I encountered same issue and simply fixed by changing 2 files as you submited. 👍

@bjones1

This comment has been minimized.

Member

bjones1 commented Feb 24, 2018

@DCMMC, note that #3233 should also fix this -- would you mind testing it as well?

@DCMMC

This comment has been minimized.

DCMMC commented Feb 24, 2018

@bjones1 It seems your approach covers more situations 👍 , I will have a try today.

@DCMMC

This comment has been minimized.

DCMMC commented Feb 24, 2018

@bjones1 I just tried your pyqt5_fix branch , it performanced perfect in Linux ( Arch Linux ). Unfortunately, in
Windows 10 with Anaconda(latest, completely new install, PyQt 5.6 ), when I ran a PyQt5 demo (with Qml ), I encountered an error 😩 :

Cannot find existing PyQt5 plugin directories

Full recent call tracks:

552 INFO: PyInstaller: 3.4.dev0+a954790b6
552 INFO: Python: 3.6.4
555 INFO: Platform: Windows-10-10.0.14393-SP0
556 INFO: wrote C:\Users\DCMMC\Desktop\pyqt5-webkit\demo.spec
562 INFO: UPX is not available.
562 INFO: Removing temporary files and cleaning cache in C:\Users\DCMMC\AppData\Roaming\pyinstaller
788 INFO: Extending PYTHONPATH with paths
['C:\\Users\\DCMMC\\Desktop\\pyqt5-webkit',
 'C:\\Users\\DCMMC\\Desktop\\pyqt5-webkit']
792 INFO: checking Analysis
798 INFO: Building Analysis because out00-Analysis.toc is non existent
801 INFO: Initializing module dependency graph...
820 INFO: Initializing module graph hooks...
826 INFO: Analyzing base_library.zip ...
5143 INFO: running Analysis out00-Analysis.toc
5146 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\dcmmc\anaconda3\python.exe
5837 INFO: Caching module hooks...
5843 INFO: Analyzing C:\Users\DCMMC\Desktop\pyqt5-webkit\demo.py
5995 INFO: Loading module hooks...
5995 INFO: Loading module hook "hook-encodings.py"...
6138 INFO: Loading module hook "hook-pydoc.py"...
6139 INFO: Loading module hook "hook-PyQt5.py"...
6143 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
6383 WARNING: Unable to find Qt5 translations at C:/Users/builder/mc3/conda-bld/qt_1505945264697/_h_env/Library/translations. Translations not packaged.
6383 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
Traceback (most recent call last):
  File "c:\users\dcmmc\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\dcmmc\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\DCMMC\Anaconda3\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 94, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 791, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 737, in build
    exec(text, spec_namespace)
  File "<string>", line 16, in <module>
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 213, in __init__
    self.__postinit__()
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 161, in __postinit__
    self.assemble()
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 472, in assemble
    module_hook.post_graph()
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 410, in post_graph
    self._load_hook_module()
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 377, in _load_hook_module
    self.hook_module_name, self.hook_filename)
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\compat.py", line 744, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 823, in load_module
  File "<frozen importlib._bootstrap_external>", line 682, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 684, in _load
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\hooks\hook-PyQt5.QtGui.py", line 11, in <module>
    hiddenimports, binaries, datas = add_qt5_dependencies(__file__)
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 490, in add_qt5_dependencies
    more_binaries = qt_plugins_binaries(plugin, namespace=namespace)
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 117, in qt_plugins_binaries
    pdir = qt_plugins_dir(namespace=namespace)
  File "c:\users\dcmmc\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 102, in qt_plugins_dir
    """.format(namespace, ", ".join(paths)))
Exception:
            Cannot find existing PyQt5 plugin directories
            Paths checked: C:/Users/builder/mc3/conda-bld/qt_1505945264697/_h_env/Library/plugins

After some simple debug in ...PyInstaller\utils\hooks\qt.py, I found PyQt5.QtCore.QLibraryInfo.location() return wrong infomations about all paths associated with PyQt5 ( P.S. PyQt5 was preinstalled by Anaconda .)

As an similar issue in SOF say, the simplest solution is uninstall Anaconda and reinstall pure python... If there other better solution? 😉

@bjones1

This comment has been minimized.

Member

bjones1 commented Feb 26, 2018

@DCMMC, thanks for testing. Yes, my PR depends on a working QLibraryInfo, which is broken in conda's distro, unfortunately. I'd think that a qt.conf file at QCoreApplication::applicationDirPath() would fix this, per the Qt docs -- does that help?

(Of course, using a fully-working PyQt5 installation per the SOF advice will also work...)

@DCMMC

This comment has been minimized.

DCMMC commented Feb 27, 2018

@bjones1 I used hard-coded path to solve the problem. It make sense to take your advice. Alternative, using subprocess.run(["qmake", "-query"]) ( @ since 3.5 ) is a good aprroach I think as well.

BTW, when I ran your fix branch in ArchLinux, pyinstaller failed because in my system -- PyQt5 has TranslationsPath existed, but not all modules have translation file (i.e., *.qm) in some cases. Therefore, I'd like to fix one place in function add_qt5_dependencies at .../PyInstaller/utils/hooks/qt.py:

Fixed

....
datas = [(os.path.join(tp, tb + '_*.qm'),
                  os.path.join('PyQt5', 'Qt', 'translations'))
                  for tb in translations_base]
....

to

datas = [(os.path.join(tp, tb + '_*.qm'),
                  os.path.join('PyQt5', 'Qt', 'translations'))
                 # additionally determine if file is existes
                 for tb in filter(lambda p: os.path.exists(p), translations_base)]
@bjones1

This comment has been minimized.

Member

bjones1 commented Feb 27, 2018

Good point -- thanks. I'll update my PR. Thanks for testing!

@bjones1

This comment has been minimized.

Member

bjones1 commented Feb 27, 2018

Hmmm, I'm looking at fixing this and I'm confused. Would you provide the error message that PyInstaller generates when you don't include the fix?

@DCMMC

This comment has been minimized.

DCMMC commented Mar 3, 2018

@bjones1

Sorry for the late reply 😳.

Files in /usr/share/qt/translations/

2018-03-03 19-35-15

Before fix

2018-03-03 19-31-13

After fix

158 INFO: PyInstaller: 3.4.dev0+a954790b6
158 INFO: Python: 3.6.4
158 INFO: Platform: Linux-4.15.5-1-ARCH-x86_64-with-arch
159 INFO: wrote /home/kevin/Projects/pyqt5-demo/demo.spec
160 INFO: UPX is not available.
161 INFO: Extending PYTHONPATH with paths
['/home/kevin/Projects/pyqt5-demo', '/home/kevin/Projects/pyqt5-demo']
161 INFO: checking Analysis
199 INFO: Building because inputs changed
199 INFO: Initializing module dependency graph...
204 INFO: Initializing module graph hooks...
205 INFO: Analyzing base_library.zip ...
2729 INFO: running Analysis out00-Analysis.toc
2763 INFO: Caching module hooks...
2765 INFO: Analyzing /home/kevin/Projects/pyqt5-demo/demo.py
2823 INFO: Loading module hooks...
2824 INFO: Loading module hook "hook-xml.py"...
3037 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
3138 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
3230 INFO: Loading module hook "hook-pydoc.py"...
3231 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
3251 INFO: Loading module hook "hook-PyQt5.py"...
3254 INFO: Loading module hook "hook-PyQt5.QtWebKit.py"...
3578 INFO: Loading module hook "hook-encodings.py"...
3647 INFO: Loading module hook "hook-PyQt5.QtNetwork.py"...
3689 INFO: Loading module hook "hook-PyQt5.QtWebKitWidgets.py"...
3975 INFO: Loading module hook "hook-PyQt5.QtQuick.py"...
4154 INFO: Loading module hook "hook-PyQt5.QtQml.py"...
4235 INFO: Loading module hook "hook-PyQt5.QtPrintSupport.py"...
4325 INFO: Loading module hook "hook-PyQt5.QtSensors.py"...
4390 INFO: Looking for ctypes DLLs
4390 INFO: Analyzing run-time hooks ...
4393 INFO: Including run-time hook 'pyi_rth_qt5.py'
4413 INFO: Looking for dynamic libraries
ldd: warning: you do not have execution permission for `/usr/lib/libgcc_s.so.1'
ldd: warning: you do not have execution permission for `/usr/lib/libgssapi_krb5.so.2'
ldd: warning: you do not have execution permission for `/usr/lib/libk5crypto.so.3'
ldd: warning: you do not have execution permission for `/usr/lib/libkrb5support.so.0'
ldd: warning: you do not have execution permission for `/usr/lib/libnettle.so.6'
ldd: warning: you do not have execution permission for `/usr/lib/libhogweed.so.4'
ldd: warning: you do not have execution permission for `/usr/lib/libkrb5.so.3'
ldd: warning: you do not have execution permission for `/usr/lib/libacl.so.1'
8895 INFO: Looking for eggs
8895 INFO: Using Python library /usr/lib/libpython3.6m.so.1.0
8898 INFO: Warnings written to /home/kevin/Projects/pyqt5-demo/build/demo/warndemo.txt
8932 INFO: Graph cross-reference written to /home/kevin/Projects/pyqt5-demo/build/demo/xref-demo.html
9004 INFO: checking PYZ
9005 INFO: Building because toc changed
9005 INFO: Building PYZ (ZlibArchive) /home/kevin/Projects/pyqt5-demo/build/demo/out00-PYZ.pyz
9271 INFO: Building PYZ (ZlibArchive) /home/kevin/Projects/pyqt5-demo/build/demo/out00-PYZ.pyz completed successfully.
9276 INFO: checking PKG
9319 INFO: Building because toc changed
9319 INFO: Building PKG (CArchive) out00-PKG.pkg
53170 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
53232 INFO: Bootloader /usr/lib/python3.6/site-packages/PyInstaller/bootloader/Linux-64bit/run
53232 INFO: checking EXE
53277 INFO: Building because toc changed
53277 INFO: Building EXE from out00-EXE.toc
53294 INFO: Appending archive to ELF section in EXE /home/kevin/Projects/pyqt5-demo/dist/demo
53888 INFO: Building EXE from out00-EXE.toc completed successfully.
@bjones1

This comment has been minimized.

Member

bjones1 commented Mar 5, 2018

@DCMMC, do you mind re-testing? I just pushed d6bda7a to the PyQt5 branch which should fix it, but would like to double-check.

@DCMMC

This comment has been minimized.

DCMMC commented Mar 6, 2018

@bjones1 My pleasure.

@DCMMC

This comment has been minimized.

DCMMC commented Mar 6, 2018

@bjones1 I tested your commit of pyqt5_fix branch, it performed perfect on my Arch Linux. Thinks for your hard work. 👍

Here is the output:

36 INFO: PyInstaller: 3.4.dev0
36 INFO: Python: 3.6.4
37 INFO: Platform: Linux-4.15.6-1-ARCH-x86_64-with-arch
37 INFO: wrote /home/kevin/Projects/pyqt5-demo/demo.spec
38 INFO: UPX is not available.
39 INFO: Extending PYTHONPATH with paths
['/home/kevin/Projects/pyqt5-demo', '/home/kevin/Projects/pyqt5-demo']
39 INFO: checking Analysis
86 INFO: Building because /usr/lib/python3.6/site-packages/PyInstaller/loader/rthooks/pyi_rth_qt5.py changed
86 INFO: Initializing module dependency graph...
89 INFO: Initializing module graph hooks...
90 INFO: Analyzing base_library.zip ...
3032 INFO: running Analysis out00-Analysis.toc
3084 INFO: Caching module hooks...
3088 INFO: Analyzing /home/kevin/Projects/pyqt5-demo/demo.py
3178 INFO: Loading module hooks...
3178 INFO: Loading module hook "hook-xml.py"...
3408 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
3596 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtbase_*.qm. These translations were not packaged.
3597 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
3665 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtbase_*.qm. These translations were not packaged.
3666 INFO: Loading module hook "hook-pydoc.py"...
3667 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
3693 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtbase_*.qm. These translations were not packaged.
3693 INFO: Loading module hook "hook-PyQt5.py"...
3694 INFO: Loading module hook "hook-PyQt5.QtWebKit.py"...
4153 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtdeclarative_*.qm. These translations were not packaged.
4153 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtbase_*.qm. These translations were not packaged.
4155 INFO: Loading module hook "hook-encodings.py"...
4205 INFO: Loading module hook "hook-PyQt5.QtNetwork.py"...
4266 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtbase_*.qm. These translations were not packaged.
4267 INFO: Loading module hook "hook-PyQt5.QtWebKitWidgets.py"...
4598 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtdeclarative_*.qm. These translations were not packaged.
4598 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtbase_*.qm. These translations were not packaged.
4600 INFO: Loading module hook "hook-PyQt5.QtQuick.py"...
4740 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtdeclarative_*.qm. These translations were not packaged.
4741 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtbase_*.qm. These translations were not packaged.
4978 INFO: Loading module hook "hook-PyQt5.QtQml.py"...
5062 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtdeclarative_*.qm. These translations were not packaged.
5062 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtbase_*.qm. These translations were not packaged.
5063 INFO: Loading module hook "hook-PyQt5.QtPrintSupport.py"...
5162 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtbase_*.qm. These translations were not packaged.
5164 INFO: Loading module hook "hook-PyQt5.QtSensors.py"...
5206 WARNING: Unable to find Qt5 translations /usr/share/qt/translations/qtbase_*.qm. These translations were not packaged.
5220 INFO: Looking for ctypes DLLs
5220 INFO: Analyzing run-time hooks ...
5222 INFO: Including run-time hook 'pyi_rth_qt5.py'
5226 INFO: Looking for dynamic libraries
ldd: 警告: 你没有执行权限  `/usr/lib/libgcc_s.so.1'
ldd: 警告: 你没有执行权限  `/usr/lib/libacl.so.1'
ldd: 警告: 你没有执行权限  `/usr/lib/libnettle.so.6'
ldd: 警告: 你没有执行权限  `/usr/lib/libk5crypto.so.3'
ldd: 警告: 你没有执行权限  `/usr/lib/libgssapi_krb5.so.2'
ldd: 警告: 你没有执行权限  `/usr/lib/libhogweed.so.4'
ldd: 警告: 你没有执行权限  `/usr/lib/libkrb5.so.3'
ldd: 警告: 你没有执行权限  `/usr/lib/libkrb5support.so.0'
11412 INFO: Looking for eggs
11412 INFO: Using Python library /usr/lib/libpython3.6m.so.1.0
11415 INFO: Warnings written to /home/kevin/Projects/pyqt5-demo/build/demo/warndemo.txt
11438 INFO: Graph cross-reference written to /home/kevin/Projects/pyqt5-demo/build/demo/xref-demo.html
11517 INFO: checking PYZ
11527 INFO: Building because toc changed
11527 INFO: Building PYZ (ZlibArchive) /home/kevin/Projects/pyqt5-demo/build/demo/out00-PYZ.pyz
11778 INFO: Building PYZ (ZlibArchive) /home/kevin/Projects/pyqt5-demo/build/demo/out00-PYZ.pyz completed successfully.
11782 INFO: checking PKG
11841 INFO: Building because toc changed
11841 INFO: Building PKG (CArchive) out00-PKG.pkg
56366 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
56395 INFO: Bootloader /usr/lib/python3.6/site-packages/PyInstaller/bootloader/Linux-64bit/run
56395 INFO: checking EXE
56441 INFO: Building because toc changed
56442 INFO: Building EXE from out00-EXE.toc
56455 INFO: Appending archive to ELF section in EXE /home/kevin/Projects/pyqt5-demo/dist/demo
56618 INFO: Building EXE from out00-EXE.toc completed successfully.
@bjones1

This comment has been minimized.

Member

bjones1 commented Mar 6, 2018

Thanks for the testing! I appreciate it.

@dashesy

This comment has been minimized.

dashesy commented Apr 24, 2018

@user-na thanks
Running 3.3.1 (on Windows) the only way it works is to add a qt.conf to the root like

[Paths]
Prefix = PyQt5/Qt

Or copying copying the content of ./PyQt5/Qt/plugins to ./ like what you mentioned. When I look in dist folder, there is no qt.conf. I also tried the master branch but that resulted in a new error.

@Joakoxdhalo

This comment has been minimized.

Joakoxdhalo commented Jun 18, 2018

@shadchin Thank you so much, that had worked for me.

@nomanabid

This comment has been minimized.

nomanabid commented Jul 9, 2018

@shadchin can you please tell me "I make 2 fix 082078e and 59a2330. That solved my issue." I'm also having same problem and where should put this number in? what file? which place?

@shadchin

This comment has been minimized.

shadchin commented Jul 9, 2018

@nomanabid
first file
second file
or try PyInstaller-dev :)

@nomanabid

This comment has been minimized.

nomanabid commented Jul 10, 2018

thank you man for the info.. just wanna ask before taking action.. is this the same in PyQt4?

@nomanabid

This comment has been minimized.

nomanabid commented Jul 10, 2018

@shadchin

This comment has been minimized.

shadchin commented Jul 10, 2018

Sorry, I don't know, I worked with PyQt5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment