1.安装Python
PyQt5通过Python安装最方便,在官网下载旧一点的版本,否则安装PyQt5时可能出现错误,这边下载的是3.9.12,下载完后安装时用自定义安装,选项勾选为所有用户安装 以及加到环境变量 (我这边只安装一个python版本),然后一直下一步就行了,傻瓜式的,不用多说。
PyCharm是python的IDE,不装也能跑PyQt5,这边暂不做安装说明。
2.安装PyQt5
用管理员权限打开windows命令行,按照以下顺序安装,使用国内的源下载,不然非常慢:
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com Sip
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com pyqt5
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com pyqt5-tools
3.可能出现的问题
(1)如果出现WARNING: Ignoring invalid distribution -ip 的警告,则去提示的目录site-packages下,删除~ip开头的目录,然后pip重新安装库即可。
(2)如果出现You are using pip version x.x.x, however version x.x.x is available. 的版本过低问题,建议是忽略不管,追求新版本不一定能带来好处。
(3)如果安装PyQt5-tools出现以下错误,则尝试使用更低版本的Python可以解决。
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
error: subprocess-exited-with-error
× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [29 lines of output]
...
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
【designer.exe】在Python安装目录下: *\Python39\Lib\site-packages\qt5_applications\Qt\bin\designer.exe
4.测试PyQt5是否安装成功
新建python文件,如HelloPyQt5.py ,填入以下代码:
import sys
from PyQt5 import QtWidgets, QtCore
app = QtWidgets.QApplication(sys.argv)
widget = QtWidgets.QWidget()
widget.resize(360,360)
widget.setWindowTitle("hello, pyqt5")
widget.show()
sys.exit(app.exec_())
然后直接双击该文件,或者在windows命令行模式下输入运行指令:
python HelloPyQt5.py
出现以下窗口说明安装成功:
5.打包成windows应用程序
(1)先安装pyinstaller
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com pyinstaller
(2)再执行打包
pyinstaller -F 文件名.py
打包后的windows可执行程序将会出现在当前运行程序的 dist 文件夹下。
|