如何在 Mac OS X 10.6 上安装 PyQt

10

我对Mac OS X还很陌生。 在安装了Python 3.1、Qt 4.6.2和SIP 4.10.1后,当我执行$ python3 configure.py命令时,遇到了以下错误。

Determining the layout of your Qt installation...
This is the GPL version of PyQt 4.7 (licensed under the GNU General Public
License) for Python 3.1 on darwin.

Type '2' to view the GPL v2 license.
Type '3' to view the GPL v3 license.
Type 'yes' to accept the terms of the license.
Type 'no' to decline the terms of the license.

Do you accept the terms of the license? yes
Checking to see if the QtGui module should be built...
Checking to see if the QtHelp module should be built...
Checking to see if the QtMultimedia module should be built...
Checking to see if the QtNetwork module should be built...
Checking to see if the QtOpenGL module should be built...
Checking to see if the QtScript module should be built...
Checking to see if the QtScriptTools module should be built...
Checking to see if the QtSql module should be built...
Checking to see if the QtSvg module should be built...
Checking to see if the QtTest module should be built...
Checking to see if the QtWebKit module should be built...
Checking to see if the QtXml module should be built...
Checking to see if the QtXmlPatterns module should be built...
Checking to see if the phonon module should be built...
Checking to see if the QtAssistant module should be built...
Checking to see if the QtDesigner module should be built...
Qt v4.6.2 free edition is being used.
Qt is built as a framework.
SIP 4.10.1 is being used.
The Qt header files are in /usr/include.
The shared Qt libraries are in /Library/Frameworks.
The Qt binaries are in /Developer/Tools/Qt.
The Qt mkspecs directory is in /usr/local/Qt4.6.
These PyQt modules will be built: QtCore.
The PyQt Python package will be installed in
/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages.
PyQt is being built with generated docstrings.
PyQt is being built with 'protected' redefined as 'public'.
The Designer plugin will be installed in
/Developer/Applications/Qt/plugins/designer.
The PyQt .sip files will be installed in
/Library/Frameworks/Python.framework/Versions/3.1/share/sip/PyQt4.
pyuic4, pyrcc4 and pylupdate4 will be installed in
/Library/Frameworks/Python.framework/Versions/3.1/bin.
Generating the C++ source for the QtCore module...
sip: Usage: sip [-h] [-V] [-a file] [-b file] [-c dir] [-d file] [-e] [-g] [-I dir] [-j #] [-k] [-m file] [-o] [-p module] [-r] [-s suffix] [-t tag] [-w] [-x feature] [-z file] [file]
Error: Unable to create the C++ code.

有人在Mac OS X 10.6.2上成功安装了PyQt吗?
6个回答

32

尝试使用brew:

brew install pyqt

现在它比macports更受推荐。


3
警告!这仅适用于使用 Brew 安装的 Python,而不是随 OS X 分发的 Python。因此,如果 PATH 中第一个 Python 是 OS X 的 Python,则它将无法正常工作。 - sorin
1
...但是您可以将PyQt的路径添加到PYTHONPATH中。实际上,Homebrew会给您提供所需的导出路径,类似于export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH。将其放入您的~/.bashrc文件中,然后您就可以开始使用了。 - Stefan van den Akker

8

使用Homebrew也可以在OSX上安装QT和PyQT。


我一直尝试通过pip和easy_install安装,但这两个软件包在安装时都有问题。你刚刚帮我省去了解决分段错误和依赖关系的麻烦。 - pocketfullofcheese

6
我和你一样遇到了同样的问题。解决方案相当简单。
由于 PyQt4 的 configure.py 中存在一个 bug,因此您的 PyQt4 源代码目录路径中不应该有空格字符。错误是由于 configure.py 在调用带有空格的输入路径上的 sip 可执行文件时出现了语法错误导致的。

简单,只需将PyQt4源文件文件夹(名为类似PyQt-mac-gpl-4.xx.x的文件夹)复制到桌面上,然后再试一次。 - Gerardo Contijoch

4

我曾经遇到过这个问题,实际上我的PyQt源文件夹在路径中的某个地方有空格字符。

我将PyQt源文件夹移动到根目录,并从那里运行python configure.py,就解决了这个问题。


1

您也可以使用PyQtX,它是适用于OS X的PyQt二进制发行版,还包括Qt库。您只需要Python即可。


1
这在OS X 10.8上无法运行,抱怨缺少官方分发的Python 2.7。考虑到事实上随OS附带的python才是默认的Python,这太荒谬了。 - sorin
如果您在安装之前阅读了要求,就会清楚地说明您需要从Python.org发行版安装Python,而不是Mac OS X自带的版本。 - AbiusX
1
这应该是正确的答案,如果您不使用brew版本的Python,那么这是最简单的解决方案。 - Jim

0

由于您正在使用 PyQt v4.7,因此您需要安装 Qt v4.7,请先安装 Qt v4.7.1


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接