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路径下的pluginsplatforms添加到系统环境变量中用户变量里。我的路径如下:D:softAnacondaLibsite-packagesPySide2pluginsplatforms
具体操作如下:
变量名:QT_QPA_PLATFORM_PLUGIN_PATH
变量值:D:softAnacondaLibsite-packagesPySide2pluginsplatforms
不同用户,变量名一致,变量值随文件位置变。
最后,保存变量后,一定要重启电脑,因为新的环境变量要重启后才能被系统识别!
**
解决方案二:
**
在程序初始部分添加如下代码:
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
代码意思是用临时系统环境变量,功能与解决方案一类似