在python3上面安裝PyQt5是十分簡單的,但是,在python2.7上安裝這個東西,着實讓人折騰了一把。要總結一下,年紀大了,記性很差。python
首先要安裝最新版的Qt和python2,命令以下:git
brew install python qt5
接下來獲取PyQt5的源碼,命令以下:github
wget http://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.6/PyQt5_gpl-5.6.tar.gz
wget http://freefr.dl.sourceforge.net/project/pyqt/sip/sip-4.18/sip-4.18.tar.gz
接下來是編譯和運行代碼:python2.7
tar -xvf sip-4.18.tar.gz cd /sip-4.18 python configure.py -d /usr/local/lib/python2.7/site-packages/ make make install cd.. tar -xvf PyQt-gpl-5.6.tar.gz cd PyQt-gpl-5.6 python configure.py -d /usr/local/lib/python2.7/site-packages/ --qmake=/usr/local/Cellar/qt5/5.6.0/bin/qmake --sip=/usr/local/bin/sip --sip-incdir=../sip-4.18/siplib make make install
注意:這裏面的sip和qmake是要看你本身的目錄的,不一樣的用戶安裝路徑可能不同。spa
接下來檢查是否安裝成功:.net
➜ PyQt5_gpl-5.6 python2 Python 2.7.15 (default, Feb 22 2019, 14:56:11) [GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import PyQt5 >>>
參考文檔:code
1 https://fredrikaverpil.github.io/2015/11/25/compiling-pyqt5-for-python-2-7-on-os-x/orm