Pyside2提示 Could not load the Qt platform plugin "windows" in "" even though it was found. 问题

问题

使用pyside2时出现如下问题,主要是缺少环境变量所致,可以直接在系统中添加或是通过代码解决。

qt.qpa.plugin: Could not load the Qt platform plugin "windows" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: direct2d, minimal, offscreen, windows.

解决

在代码头部添加如下:

import os
import PySide2
dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
发布了4 篇原创文章 · 获赞 0 · 访问量 115

猜你喜欢

转载自blog.csdn.net/u012921982/article/details/104117488