Python 如何在 Mac 上安装 PyQt5?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34583811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I install PyQt5 on Mac?
提问by user2888499
I am trying to install PyQt5 on my Mac but I do not know how to use it well. I have tried to install sip doing
我正在尝试在我的 Mac 上安装 PyQt5,但我不知道如何很好地使用它。我试图安装 sip 做
cd ~/Downloads/sip-4.17
python configure.py
which worked, and then I tried
哪个有效,然后我尝试了
cd ~/Downloads/PyQt-gpl-5.5.1
python configure.py --qmake /Users/name/Qt/5.5/clang_64/bin/qmake
which returns an error that says
它返回一个错误,说
Make sure you have a working sip on your PATH or use the --sip argument to explicitly specify a working sip.
确保您的 PATH 上有一个工作 sip 或使用 --sip 参数显式指定一个工作 sip。
How do I fix this error? Did I not install sip?
我该如何解决这个错误?我没有安装sip吗?
采纳答案by hgiesel
回答by Daniele Pantaleone
You need to install SIP first, which is not just running configure.py
:
您需要先安装 SIP,这不仅仅是运行configure.py
:
>>> cd ~/Downloads/sip-4.17
>>> python configure.py
>>> make
>>> make install
Then you can install PyQt5:
然后你可以安装PyQt5:
>>> cd ~/Downloads/PyQt-gpl-5.5.1
>>> python configure.py --qmake /Users/name/Qt/5.5/clang_64/bin/qmake
>>> make
>>> make install
回答by Christian Tismer
Meanwhile I have the ultimate way to install PyQt5 on macOS. Don't use Homebrew. It is great for installing Qt5, but for PyQt5 the best way to install it is using
同时我有在 macOS 上安装 PyQt5 的终极方法。不要使用Homebrew。它非常适合安装 Qt5,但对于 PyQt5,安装它的最佳方法是使用
python3 -m pip install PyQt5
This works very quickly and uses universal Python Wheels:
这工作得非常快,并使用通用的 Python Wheels:
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
You see: Such a wheel is re-used for CPython 3.5, 3.6 and 3.7.
您会看到:CPython 3.5、3.6 和 3.7 重新使用了这样的轮子。
Old remark, but see below: PySide2 is not as far, but we will build similar wheels when we have the first version ready.
旧评论,但请参见下文:PySide2 还没有那么远,但是当我们准备好第一个版本时,我们将构建类似的轮子。
Added on 2017/09/25: You can of course also use
于 2017/09/25 添加:您当然也可以使用
pip3 install PyQt5
But at that time my pip/pip2/pip3 was a bit messy linked, so the first solution is rock solid and avoids confusion.
但当时我的 pip/pip2/pip3 链接有点乱,所以第一个解决方案是坚如磐石的,避免了混乱。
Also right is that you don't always get the lastest version of PyQt5 this way. But for getting started, the priority is to get results quickly and not the bleeding edge.
同样正确的是,您并不总是以这种方式获得最新版本的 PyQt5。但是对于入门而言,首要任务是快速获得结果而不是前沿。
Update: PySide2 now officially has wheels, to:
更新: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
If you see bugs or differences between the two, please feel free to open a bug report. Follow the instructions on https://wiki.qt.io/Qt_for_Python/Reporting_Bugs
如果您发现错误或两者之间的差异,请随时打开错误报告。按照https://wiki.qt.io/Qt_for_Python/Reporting_Bugs上的说明进行操作
回答by Benny K
In ~/.pip/pip.log
I discovered:
在~/.pip/pip.log
我发现:
Skipping https://pypi.python.org/packages/... (from https://pypi.python.org/simple/pyqt5/) because it is not compatible with this Python
Simply installed newwer version of Python 3 from official website and pip3 install PyQt5
finally worked.
只需从官方网站安装较新版本的 Python 3 并pip3 install PyQt5
最终运行。
回答by Tamil Selvan S
Qt is set of cross-platform C++ libraries that implement high-level APIs for accessing many aspects of modern desktop and mobile systems. These include location and positioning services, multimedia, NFC and Bluetooth connectivity, a Chromium based web browser, as well as traditional UI development.
Qt 是一组跨平台的 C++ 库,它们实现了高级 API,用于访问现代桌面和移动系统的许多方面。其中包括位置和定位服务、多媒体、NFC 和蓝牙连接、基于 Chromium 的网络浏览器以及传统的 UI 开发。
PyQt5 is a comprehensive set of Python bindings for Qt v5. It is implemented as more than 35 extension modules and enables Python to be used as an alternative application development language to C++ on all supported platforms including iOS and Android.
PyQt5 是 Qt v5 的一套全面的 Python 绑定。它以超过 35 个扩展模块的形式实现,使 Python 能够在所有支持的平台(包括 iOS 和 Android)上用作 C++ 的替代应用程序开发语言。
PyQt5 may also be embedded in C++ based applications to allow users of those applications to configure or enhance the functionality of those applications.
PyQt5 也可以嵌入基于 C++ 的应用程序中,以允许这些应用程序的用户配置或增强这些应用程序的功能。
pip install PyQt5
回答by RWorden
Qt has a Mac .dmg installer with all the components. I uninstalled my pip version first, and installed my Qt into the standard location - I tried putting into /opt/Qt as suggested by another post, but it failed due to changes to MacOS rights in Mojave. There is an expansion triangle next to the Qt item which allows for installing Designer separately from the Qt engine and the 2D/3D development and platform-specific tools.
Qt 有一个包含所有组件的 Mac .dmg 安装程序。我先卸载了 pip 版本,然后将 Qt 安装到标准位置 - 我尝试按照另一篇文章的建议放入 /opt/Qt,但由于 Mojave 中 MacOS 权限的更改而失败。Qt 项旁边有一个扩展三角形,它允许将 Designer 与 Qt 引擎以及 2D/3D 开发和特定于平台的工具分开安装。
Qt Installer:
Qt安装程序: