1. 首先使用 homebrew 包管理工具安装 pyqt@5
brew install pyqt@5
2. 安装完成后记录一下安装路径
==> Pouring qt@5--5.15.8_1.arm64_ventura.bottle.tar.gz
🍺 /opt/homebrew/Cellar/qt@5/5.15.8_1: 10,840 files, 344.4MB
==> Installing pyqt@5
==> Pouring pyqt@5--5.15.7_2.arm64_ventura.bottle.tar.gz
🍺 /opt/homebrew/Cellar/pyqt@5/5.15.7_2: 3,966 files, 102MB
3. 把 PyQt5 拓展拷贝到需要开发的虚拟环境中去
因为 Mac 用 pip 无法直接安装 PyQt5,所以可以使用这种南水北调的方式
# 进入安装位置的包目录
cd opt/homebrew/Cellar/pyqt@5/5.15.7_2/lib/python3.10/site-packages
# 执行拷贝到虚拟环境
cp -r * /opt/homebrew/Caskroom/miniconda/base/envs/PyQt/lib/python3.10/site-packages
4. 验证迁移是否成功
如使用 PyCharm
时,等待 indexing
索引重新建立完成时,import PyQt5
变成了可以选中的状态
5. Pycharm 配置外部扩展工具 External Tools
5.1 配置 Qt Designer
- 找到你
Designer.app
所处位置,设置为Program
路径 Working directory
设置为$ProjectFileDir$
5.2 配置 Qt PyUIC
找到
pyuic
所处位置,设置为Program
路径,图中为第一项pyuic5
Program 参数设置为如下:
/opt/homebrew/Cellar/pyqt@5/5.15.7_2/bin/pyuic5
- Arguments 参数设置为如下:
$FileName$ -o $FileNameWithoutExtension$.py
- Working Directory 参数设置仍为:
$ProjectFileDir$
- 详情如图所示:
5.3 配置 Qt PyRRC
- 路径同上
- Program 参数设置为如下:
/opt/homebrew/Cellar/pyqt@5/5.15.7_2/bin/pyrrc5
- Arguments 参数设置为如下:
$FileName$ -o $FileNameWithoutExtension$.py
- Working Directory 参数设置仍为:
$ProjectFileDir$
- 详情如图所示: