利用 PyCharm 搭建 PyQt5 开发环境

Guide to install PyQt5 on Mac OS X with python 3.4 virtualenv

记录一下之前配置 PyQt 开发环境的步骤,最终效果: 通过 Pycharm 运行 Qt Designer 设计界面;并能从 Pycharm 中利用 PyUic 直接将工程中选定的.ui 文件转换为.py 文件

Prerequisite

  • python >= 3.2
  • Qt libraries >= 5
  • SIP 4.x
  • PyQt 5.x
  • xcode 5.x
  • Qt Designer
  • Pycharm

Dowload

Dowload SIP and PyQt5 from Riverbank

Set Virtual Environment

1
2
3
4
pip install virtualenv
virtualenv env4pyqt5
cd ./env4pyqt5
source bin/activate *run sand box('source bin/deactive' to stop)

Installation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cd /usr/bin/local
cp /Users/a15/Downloads/PyQt-gpl-5.5.tar.gz .
cp /Users/a15/Downloads/sip-4.16.9.tar.gz .
tar xvf PyQt-gpl-5.5.tar.gz
tar xvf sip-4.16.9.tar.gz
cd sip-4.16.9/
python configure.py -d ~/env4pyqt/lib/python3.4/site-packages --arch x86_64
make
sudo make install
sudo make clean
cd ../PyQt-gpl-5.5.tar.gz
python configure.py --destdir ~/env4pyqt/lib/python3.4/site-packages --qmake /Applications/5.4/clang_64/bin/qmake
make
sudo make install
sudo make clean

Test For PyQt5

1
python -c "import PyQt5"

Set Up PyQt5 On Pycharm

Use cmd + ',' to open preference in Pycharm. Look for 'External Tools'. Add tools as follow:

QtDesigner
QtDesigner
PyUic
PyUic

Parameters in '2.png':

1
-m PyQt5.uic.pyuic $FileName$ -o$FileNameWithoutExtension$.py

Usage

  • Set the python interpreter the one in your virtualenv
  • Open Tools -> External Tools -> QtDesigner to edit .ui file
  • Chose the .ui file and use Tools -> External Tools -> PyUic to transform .ui into .py