之前在旧电脑折腾了一阵子 pyqt 开发,目前用了一台新的机器,安装 pyqt 过程简单记录下,也供小伙伴参考

1 准备工作

python 版本:


Python 2.7.10 (default, Oct 23 2015, 18:05:06)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.

系统:mac OS X EI Captian 10.11.2

准备以下三个文件

  • qt-opensource-mac-x64-clang-5.6.0.dmg

  • sip-4.18.tar.gz

  • PyQt5_gpl-5.6.tar.gz

文件可以到这里下载 链接: https://pan.baidu.com/s/1o761BdC 密码: bxxj

2 安装步骤

2.1 安装 qt-opensource-mac-x64-clang-5.6.0.dmg

这个没什么好说的,点击即可,安装结束之后,修改了 .zshrc 配置

export PATH=$PATH:/Users/hello/Qt5.6.0/5.6/clang_64/bin

2.2 安装 sip-4.18.tar.gz

解压
cd sip-4.18
python configure.py
make && make install

2.3 安装 PyQt5_gpl-5.6.tar.gz

解压
cd PyQt5_gpl-5.6
python configure.py 
    -q /Users/hello/Qt5.6.0/5.6/clang_64/bin/qmake 
    -d /Library/Python/2.7/site-packages 
    -sip=/System/Library/Frameworks/Python.framework/Versions/2.7/bin/sip
make(这里需要编译一阵子,建议喝瓶啤酒,看看球赛)
make install

python configure.py 后面参数详解

  1. -q 参数后面的是 Qtqmake 位置

  2. -d 参数为 python 包的位置

  3. –-sip 参数为 sip 的位置

3 测试例子

步骤 2.3 正常安装结束之后,在 PyQt5_gpl-5.6examples 目录下有很多例子,可以运行目录下任何一个例子查看运行效果,并学习其中的代码。

cd PyQt5_gpl-5.6/examples/widgets
python calculator.py

运行结果如下: