如何在Mac上安装PyQt5?

2024-04-20 05:04:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在我的Mac上安装PyQt5,但我不知道如何使用它。我试过安装sip doing

cd ~/Downloads/sip-4.17
python configure.py

很有效,然后我试着

cd ~/Downloads/PyQt-gpl-5.5.1
python configure.py --qmake /Users/name/Qt/5.5/clang_64/bin/qmake

返回一个错误

确保路径上有一个工作sip,或者使用--sip参数显式指定一个工作sip。

如何修复此错误?我没有安装sip吗?


Tags: namepyconfiguremacdownloads错误cdgpl
3条回答

同时,我有在macOS上安装PyQt5的最终方法。 不要使用Homebrew。安装Qt5很好,但对于PyQt5,最好的安装方法是使用

python3 -m pip install PyQt5

它工作非常迅速,并使用通用Python轮子:

Collecting PyQt5
  Downloading PyQt5-5.9-5.9.1-cp35.cp36.cp37-abi3-macosx_10_6_intel.whl 
(82.2MB)
    100% |████████████████████████████████| 82.2MB 17kB/s 
Collecting sip<4.20,>=4.19.3 (from PyQt5)
  Downloading sip-4.19.3-cp36-cp36m-macosx_10_6_intel.whl (49kB)
    100% |████████████████████████████████| 51kB 1.2MB/s 
Installing collected packages: sip, PyQt5
Successfully installed PyQt5-5.9 sip-4.19.3

你看:这样的轮子被用于CPython 3.5、3.6和3.7。

旧的评论,但请看下面:PySide2并没有那么远,但我们将在第一个版本准备好后构建类似的轮子。

于2017年9月25日添加:您当然也可以使用

pip3 install PyQt5

但当时我的pip/pip2/pip3有点混乱,所以第一个解决方案是坚如磐石的,避免了混淆。

同样正确的是,您并不总是以这种方式获得PyQt5的最新版本。但要开始,首要任务是迅速取得成果,而不是急功近利。

更新:PySide2现在正式拥有了轮子,可以:

$ python3 -m pip install PySide2
Collecting pyside2
  Downloading https://files.pythonhosted.org/packages/2a/e2/2dc134a5c475f661d5ff2ab587fbd2c285db3d064e03ac9b4a2ee0958400/PySide2-5.12.2-5.12.2-cp35.cp36.cp37-abi3-macosx_10_12_intel.whl (109.8MB)
    100% |████████████████████████████████| 109.8MB 238kB/s 
Collecting shiboken2==5.12.2 (from pyside2)
  Downloading https://files.pythonhosted.org/packages/bd/8b/a2ad76c3a935fae51f0ed9b150a9df08167c4550fcd07637f0db19c31849/shiboken2-5.12.2-5.12.2-cp35.cp36.cp37-abi3-macosx_10_12_intel.whl (691kB)
    100% |████████████████████████████████| 696kB 1.6MB/s 
Installing collected packages: shiboken2, pyside2
Successfully installed pyside2-5.12.2 shiboken2-5.12.2

如果你发现了bug或者两者之间的差异,请随时打开bug报告。按照https://wiki.qt.io/Qt_for_Python/Reporting_Bugs上的说明操作

我有点回避这个问题,但最简单的方法是安装Homebrew,然后运行brew install pyqtbrew install pyqt5

您需要先安装SIP,它不仅仅运行configure.py

>>> cd ~/Downloads/sip-4.17
>>> python configure.py
>>> make
>>> make install

然后可以安装PyQt5:

>>> cd ~/Downloads/PyQt-gpl-5.5.1
>>> python configure.py --qmake /Users/name/Qt/5.5/clang_64/bin/qmake
>>> make
>>> make install

相关问题 更多 >