当前位置:首页 » 《休闲阅读》 » 正文

解决“This application failed to start because no Qt platform plugin could be initialized.”问题一例

0 人参与  2024年04月27日 10:05  分类 : 《休闲阅读》  评论

点击全文阅读


问题描述:

在python程序中调用了某个需要pyqt的包,运行中出现报错:
qt.qpa.plugin: Could not find the Qt platform plugin “windows” in “”
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
机器是windows11系统,已经安装过pyqt5。

失败尝试:

在windows power shell中运行pip show pyqt5,得到pytq5的安装路径为:
C:\Users…\LocalCache\local-packages\Python311\site-packages (部分路径省略)
则相应的Qt的环境路径为:
C:\Users…\LocalCache\local-packages\Python311\site-packages\PyQt5\Qt5\plugins\platforms
曾尝试在windows11的环境变量中加入名为“QT_QPA_PLATFORM_PLUGIN_PATH”的环境变量,变量内容为以上Qt的环境路径(在Win11中间添加环境变量的具体方法可以很容易在网上搜到。由于这个方法最终无效,所以就不在这里详细说明了。):
在Win11中间加入环境变量。具体方法可以很容易在网上搜到。由于这个方法最终无效,所以就不在这里详细说明了。
结果添加环境变量之后问题并没有解决。

成功尝试:

在python代码中加入以下代码:

import os, PyQt5dirname = os.path.dirname(PyQt5.__file__)qt_dir = os.path.join(dirname, 'Qt5', 'plugins', 'platforms')os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = qt_dir

问题解决。


点击全文阅读


本文链接:http://zhangshiyu.com/post/100905.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1