vscode import pyside2 error
https://blog.csdn.net/weixin_43917589/article/details/106137952
亲测有效,一招解决错误:This application failed to start because not Qt platform plugin could be initialized.
运行Pyside2时出现如下图所示错误:
错误内容:This application failed to start because not Qt platform plugin could be initialized.Reinstalling the application may fix this problem.
解决方案一:此方法一劳永逸。
将PySide2路径下的plugins\platforms添加到系统环境变量中用户变量里。我的路径如下:D:\soft\Anaconda\Lib\site-packages\PySide2\plugins\platforms
具体操作如下:
变量名:QT_QPA_PLATFORM_PLUGIN_PATH
变量值:D:\soft\Anaconda\Lib\site-packages\PySide2\plugins\platforms
不同用户,变量名一致,变量值随文件位置变。
最后,保存变量后,一定要重启电脑,因为新的环境变量要重启后才能被系统识别!
**
解决方案二:
**
在程序初始部分添加如下代码:
dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
1
2
3
代码意思是用临时系统环境变量,功能与解决方案一类似
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步