E:>E:\Python37\python.exe -m pip install PySide2
Collecting PySide2
Using cached https://files.pythonhosted.org/packages/a0/d3/5e8811ddc6c0e794c26
c87eb9c32e66930a46d6b19e61cbce79e5c5f6865/PySide2-5.14.1-5.14.1-cp35.cp36.cp37.c
p38-none-win_amd64.whl
Requirement already satisfied: shiboken2==5.14.1 in E:\python37\lib\site-
packages (from PySide2) (5.14.1)
Installing collected packages: PySide2
Successfully installed PySide2-5.14.1
也可以手动下载安装: PySide2-5.14.1-5.14.1-cp35.cp36.cp37.cp38-none-win_amd64.whl
离线
# This Python file uses the following encoding: utf-8
import sys,os
import PySide2
from PySide2.QtWidgets import QApplication, QMainWindow
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
if __name__ == "__main__":
app = QApplication([])
window = MainWindow()
window.show()
sys.exit(app.exec_())
不知道是不是由于安装了 PyQt5 冲突的缘故, 报如下错误:
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.
离线
找到解决方案了: https://blog.csdn.net/ouening/article/details/81093697
# This Python file uses the following encoding: utf-8
import sys,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
from PySide2.QtWidgets import QApplication, QMainWindow
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
if __name__ == "__main__":
app = QApplication([])
window = MainWindow()
window.show()
sys.exit(app.exec_())
离线