PyCharm+PySide2运行GUI程序时报错:this application failed to start because no Qt platform pliugin could...

##解决 PyCharm+PySide2运行GUI程序时报错:
在这里插入图片描述
在安装pyside2的目录中找到_init_.py(我的是E:\anaconda3\Lib\site-packages\PySide2)打开并在def _setupQtDirectories():中添加以下代码:

import sys, os
    dirname = os.path.dirname(__file__)
    plugin_path = os.path.join(dirname, 'plugins', 'platforms')
    os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path

修改成这样子:
在这里插入图片描述
保存后运行。
若还有错,注意是否已经配置好了用户的环境变量
配置环境变量的方式如下:
此电脑右键——>属性
在这里插入图片描述
高级系统设置
在这里插入图片描述
环境变量
在这里插入图片描述
在用户系统变量中新建:变量名为:QT_QPA_PLATFORM_PLUGIN_PATH
变量值为PySide2\plugin\platforms
在这里插入图片描述
点击确定。
重启电脑运行程序,问题解决!

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
出"This application failed to start because no Qt platform plugin could be initialized"错误是因为在pycharm运行程序缺少Qt平台插件的库文件。这个错误通常发生在缺少xcb库文件或者没有正确配置Qt平台插件路径的情况下。 解决这个问题的方法是确保正确安装了Qt平台插件,并将插件路径配置到环境变量中。 首先,你可以尝试重新安装应用程序,这可能会修复问题。如果问题仍然存在,可以按照以下步骤解决问题: 1. 找到你的Qt平台插件的路径,通常是在你的pycharm安装目录下的qt/plugins文件夹中。 2. 打开pycharm,点击"File",然后选择"Settings"。 3. 在"Settings"窗口中,选择"Build, Execution, Deployment",然后选择"Python Interpreter"。 4. 在"Python Interpreter"页签中,选择你的项目的解释器。 5. 在右侧的"Environment"字段中,点击编辑按钮。 6. 在编辑环境变量的对话框中,添加一个新的环境变量,名称为"QT_QPA_PLATFORM_PLUGIN_PATH",值为Qt平台插件的路径。 7. 点击确定保存更改。 现在,重新运行程序,应该就能够正常启动了。如果问题仍然存在,可能是由于其他问题引起的,你可以尝试重新安装Qtpycharm,或者在开发环境中查找其他解决方案。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [This application failed to start because no Qt platform plugin could be initialized. Reinstalling th](https://blog.csdn.net/weixin_45297905/article/details/127703251)[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_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [成功解决This application failed to start because no Qt platform plugin could be initialized.](https://blog.csdn.net/weixin_62087061/article/details/128910228)[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_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值