跨境派

跨境派

跨境派,专注跨境行业新闻资讯、跨境电商知识分享!

当前位置:首页 > 卖家故事 > 解决“This application failed to start because no Qt platform plugin could be initialized.”问题一例

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

时间:2024-04-17 11:40:27 来源:网络cs 作者:晨起 栏目:卖家故事 阅读:

标签: 解决 
阅读本书更多章节>>>>

问题描述:

在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

问题解决。

阅读本书更多章节>>>>

本文链接:https://www.kjpai.cn/gushi/2024-04-17/159732.html,文章来源:网络cs,作者:晨起,版权归作者所有,如需转载请注明来源和作者,否则将追究法律责任!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。

文章评论