Python3+Qt5搭建Python的界面开发环境

xingyun86 2021-4-8 920

Python3+Qt5搭建Python的界面开发环境

1.搭建Python3环境

Linux下:sudo apt install python3即可

Windows下:建议使用Python3.7.3的版本(大于3.7.3版本不同的Windows依赖库很不友好的)

2.安装pyqt5依赖

python -m pip install update pip
python -m pip install PyQt5
python -m pip install PyQt5-Tools
python -m pip install PyQtWebEngine

如果遇到以下错误:

错误a: Could not find QtWebEngineProcess.exe
解决办法:检查python路径是否有中文,如果有,请消除中文路径。

错误b: qt.qpa.plugin: Could not find the Qt platform plugin "windows"

windows下需配置环境变量:

QT_QPA_PLATFORM_PLUGIN_PATH
X:\Python37x64\Lib\site-packages\PyQt5\Qt\plugins


3.测试pyqt5环境

保存以下内容到testqt5.py:

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtCore import QCoreApplication
if __name__ == '__main__':
    app = QApplication(sys.argv)    
    btn = QPushButton("Hello PyQt5")
    btn.clicked.connect(QCoreApplication.instance().quit)
    btn.resize(400,100)
    btn.move(50,50)
    btn.show()
    sys.exit(app.exec_())

4.运行结果

python testqt5.py


安装完成

×
打赏作者
最新回复 (0)
只看楼主
全部楼主
返回