python中This application failed to start because no Qt platform plugin could be initialized.

之前想要学习利用python编辑GUI ,结果第一步弄了一天,就是这个问题,原代码如下

//  
import sys
from PyQt5.QtWidgets import QApplication, QWidget


if __name__ == '__main__':

    app = QApplication(sys.argv)

    w = QWidget()
    w.resize(250, 150)
    w.move(300, 300)
    w.setWindowTitle('Simple')
    w.show()

    sys.exit(app.exec_())

但是每一次运行都会报错,This application failed to start because no Qt platform plugin could be initialized.
更改如下

//更改之后
import sys
import PySide2
import os
dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
from PySide2.QtWidgets import QApplication, QWidget


if __name__ == '__main__':

    app = QApplication(sys.argv)

    w = QWidget()
    w.resize(250, 150)
    w.move(300, 300)
    w.setWindowTitle('Simple')
    w.show()

    sys.exit(app.exec_())

可以用了

这个错误提示"This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem."通常是由于缺少Qt平台插件导致的。对于Windows系统上使用pyqt打开designer.exe报错的情况,解决方法是将"PyQt5"和"pyqt5_plugins"两个文件夹从"Python\Python311\Lib\site-packages"复制到Python\Python311\Lib安装目录下。这样可以确保Qt平台插件被正确初始化,从而解决该问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [解决This application failed to start because no Qt platform plugin could be initialized. ...](https://blog.csdn.net/weixin_41194171/article/details/109447227)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [问题:This application failed to start because no Qt platform plugin could be initialized....](https://blog.csdn.net/weixin_55609727/article/details/130558657)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值