PyInstaller生成的exe文件错误:qt.qpa.plugin:即使找到了,也无法在“”中加载qt平台插件“ windows”

问题描述 投票:0回答:1

我创建了一个程序来从驱动器上的文件中读取某些数据,在PyQt5 ui上显示结果,并接受用户的更正。

该程序作为python文件运行时工作正常。但是,当我使用PyInstaller将其转换为独立的exe时,在需要启动pyqt5 gui的情况下,它仍然可以正常工作。此时,它将停止引发以下错误:

qt.qpa.plugin:即使找到了Qt平台插件“ windows”,也无法在“”中加载它。此应用程序无法启动,因为无法初始化Qt平台插件。重新安装该应用程序可能会解决此问题。可用的平台插件为:最小,屏幕外,窗口。

我已经阅读了thisthisthis,但它们不能解决我的问题。

gui的代码很大,但这是结构:

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)

该代码已转换为具有以下参数的独立exe:

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

您知道如何解决此问题吗?

谢谢

python python-3.x pyqt pyqt5 pyinstaller
1个回答
0
投票

我在编译的应用程序中遇到了相同的错误消息。

[为了解决这个问题,我首先以最少的导入将应用程序分解为它的框架,该文件在编译时可以完美工作。然后,我将部分导入的“大”应用程序全部重新添加回去,直到错误再次出现。

最后(至少对我来说)pandas是元凶:

最小复制实例,这有效:

from PyQt5 import QtWidgets

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

此(在第2行中添加了熊猫导入)会抛出您描述的错误:

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

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

但是,当第一次导入熊猫然后再导入PyQt 5时,我的编译版本再次起作用:

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

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

因此,在我的情况下,解决方案是跟踪“错误的导入”,摆弄导入顺序并获得幸运(我太缺乏经验了,甚至无法理解导入顺序导致此错误的原因)

如果您不使用熊猫,也许整个“扎到骨架并开始逐块导入”的方法将帮助您进一步弄清错误的根本原因。

[如果您使用的是熊猫,但切换顺序没有帮助,there is another thread描述了尝试处理熊猫编译问题的方法。

© www.soinside.com 2019 - 2024. All rights reserved.