简体   繁体   中英

PyInstaller generated exe file error : qt.qpa.plugin: could not load the qt platform plugin "windows" in "" even though it was found

I have created a program to read certain data from files on a drive, display results on a PyQt5 ui and accept corrections if any from user.

The program worked fine when run as a python file. However, when i converted it into a standalone exe using PyInstaller, it works fine upto the point where the pyqt5 gui needs to be launched. At this point, it stops throwing 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. Available platform plugins are: minimal, offscreen, windows.

I have read this , this and this but they dont resolve my issue.

The code of the gui is very big but here is the structure :

from PyQt5 import uic, QtWidgets
import sys
import os

#baseUIClass, baseUIWidget = uic.loadUiType('gui.ui')
baseUIClass, baseUIWidget = uic.loadUiType(r'C:\mypath\gui.ui')

class Ui(baseUIClass, baseUIWidget ):

    def __init__(self, *args, **kwargs):
        baseUIWidget.__init__(self, *args, **kwargs)
        self.setupUi(self)

# More code to perform the desired actions

def run(input_variables):
    app = QtWidgets.QApplication(sys.argv)
    ui = Ui()
    ui.show()
# More code to make the Ui perform desired actions
    app.exec_()
    return(output_variables)

The code was converted to a standalone exe with the following arguments :

pyinstaller --hiddenimport <hidden import> --onefile <python filename>

Would you know how to troubleshoot this please?

Thanks

I ran into the same error message with my compiled application.

To track down the issue, I first stripped down the app to its skeleton with minimal imports, which worked flawlessly when compiled. I then partially added back all imports of my "big" application until the error reappeared.

In the end (for me at least) pandas is the culprit:

Minimal reproducibale examples, this works:

from PyQt5 import QtWidgets

app = QtWidgets.QApplication([])
window = QtWidgets.QMainWindow()
window.show()
app.exec()

This (added pandas import in line 2) throws the error you describe:

from PyQt5 import QtWidgets
import pandas as pd  # import after pyqt5

app = QtWidgets.QApplication([])
window = QtWidgets.QMainWindow()
window.show()
app.exec()

However, when first importing pandas and then importing PyQt 5, my compiled version works again:

import pandas as pd  # import before pyqt5
from PyQt5 import QtWidgets

app = QtWidgets.QApplication([])
window = QtWidgets.QMainWindow()
window.show()
app.exec()

So, in my case the solution was to track down the "erroneous import", fiddle with the import order and get lucky (I am far too unexperienced to even try to understand why the import order leads to this error)

If you are not using pandas, maybe the whole "strip down to skeleton and start importing piece by piece"-approach will help you to further clarify the root cause of the error.

If you are using pandas and the order switch-up did not help, there is another thread which describes which tries to deal with pandas compiling issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM