原文地址:http://www.cnblogs.com/JohnABC/p/6232973.html 下面內容略微不同
環境:
系統: OS X 10.11.4
Python: 2.7.10
1.安裝 Qt
brew install qt
測試安裝結果,需要正確找到 qmake 的路徑
qmake (安裝完我輸qmake沒反應,需要到qt的安裝路徑去找#/usr/local/Cellar/qt/5.9.1/bin/qmake)
2.安裝 SIP
下載(sip-4.18.1.tar.gz): https://riverbankcomputing.com/software/sip/download (我用迅雷下的用tar解壓不了,用瀏覽器默認下載的正常)
tar -xzf sip-4.18.1.tar.gz cd sip-4.18.1 python configure.py -d /Library/Python/2.7/site-packages --arch=x86_64 make sudo make install
#如果 sudo make install 的時候報如下錯誤
cp -f sip /System/Library/Frameworks/Python.framework/Versions/2.7/bin/sip cp: /System/Library/Frameworks/Python.framework/Versions/2.7/bin/sip: Operation not permitted make[1]: *** [install] Error 1 make: *** [install] Error 2
#解決方法
#重啟 Mac
#按住 Command + R 直到出現蘋果 Logo
#進入 Recoverary 模式
#菜單欄 > 實用工具 > 終端
#輸入 csrutil disable (如果想再次改回來,輸入 csrutil enable)
#重啟 Mac
3.PyQt4
下載(PyQt-mac-gpl-4.11.4.tar.gz): https://riverbankcomputing.com/software/pyqt/download (我用迅雷下的用tar解壓不了,用瀏覽器默認下載的正常)
查看 qmake 路徑
which qmake #/usr/local/bin/qmake
(我使用which qmake找不到qmake路徑,需要到qt的安裝路徑去找#/usr/local/Cellar/qt/5.9.1/bin/qmake)
安裝
安裝時出現報錯:Error: This version of PyQt4 and the commercial version of Qt have incompatible licenses.
解決方法:注釋掉configure-ng.py下面語句即可:
if introspecting and target_config.qt_licensee not in OPEN_SOURCE_LICENSEES and ltype == 'GPL':
error(
"This version of PyQt4 and the commercial version of Qt have "
"incompatible licenses.")
tar -xzf PyQt-mac-gpl-4.11.4.tar.gz cd PyQt-mac-gpl-4.11.4 python configure-ng.py -q /usr/local/bin/qmake -d /Library/Python/2.7/site-packages/ --sip /System/Library/Frameworks/Python.framework/Versions/2.7/bin/sip make sudo make install
4.測試
import PyQt4

