pyQt4 for mac OS 10.8
Posted VindyLeong 一个略神经病的程
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pyQt4 for mac OS 10.8相关的知识,希望对你有一定的参考价值。
版权声明:本文为博主原创文章,未经博主允许不得转载。
因为想跨平台,所以考虑Qt,又想结合脚本的便捷。考虑PyQt
网上搜索了一下,资料挺少的。有的还是以前的资料。
参考这里 http://www.noktec.be/Python/how-to-install-pyqt4-on-osx
1:下载安装Qt
http://qt-project.org/downloads
我下载的是Qt 5.0.2 for Mac (404 MB) (Info)
安装起来还挺方便的。不说了
2:下载SIP
http://www.riverbankcomputing.co.uk/software/sip/download
我下载的是 sip-4.14.7-snapshot-bd9eccac4407.tar.gz
下载以后解压
- cd sip-4.14.7-snapshot-bd9eccac4407
- python configure.py -d /Library/Python/2.7/site-packages --arch=i386
- make
- sudo make install
安装起来没问题。
3:下载PyQt4
http://www.riverbankcomputing.co.uk/software/pyqt/download
我下载的是 PyQt-mac-gpl-snapshot-4.10.2-ffcf323516fc.tar.gz
下载后解压安装配置这里要参考改版后的配置文档,新版本用的是configure-ng.py:
http://pyqt.sourceforge.net/Docs/PyQt4/installation.html#configuring-pyqt4
命令
- cd PyQt-mac-gpl-snapshot-4.10.2-ffcf323516fc
- python configure-ng.py -q /Users/watsy/Qt5.0.2/5.0.2/clang_64/bin/qmake -d /Library/Python/2.7/site-packages/ --sip /System/Library/Frameworks/Python.framework/Versions/2.7/bin/sip
- make
- sudo make install
以上步骤完成以后,运行demo
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- """
- ZetCode PyQt4 tutorial
- In this example, we create a simple
- window in PyQt4.
- author: Jan Bodnar
- website: zetcode.com
- last edited: October 2011
- """
- import sys
- from PyQt4 import QtGui
- def main():
- app = QtGui.QApplication(sys.argv)
- w = QtGui.QWidget()
- w.resize(250, 150)
- w.move(300, 300)
- w.setWindowTitle(‘Simple‘)
- w.show()
- sys.exit(app.exec_())
- if __name__ == ‘__main__‘:
- main()
执行得到如下错误
- Traceback (most recent call last):
- File "pyqtDemo.py", line 16, in <module>
- from PyQt4 import QtGui
- ImportError: dlopen(/Library/Python/2.7/site-packages/sip.so, 2): no suitable image found. Did find:
- /Library/Python/2.7/site-packages/sip.so: mach-o, but wrong architecture
在考虑是什么问题
查看
- lipo -info /Library/Python/2.7/site-packages/sip.so
得到
- Non-fat file: /Library/Python/2.7/site-packages/sip.so is architecture: i386
想来现在机器用的是64位系统了。
修改 sip的配置从新编译
- cd sip-4.14.7-snapshot-bd9eccac4407
- python configure.py -d /Library/Python/2.7/site-packages --arch=x86_64
- make
- sudo make install
安装碗以后运行demo
perfect~
以上是关于pyQt4 for mac OS 10.8的主要内容,如果未能解决你的问题,请参考以下文章
PyQt5 在Mac 10.12系统运行提示错误(which was built for Mac OS X 10.13)