某个组件。我觉得应该是这样吧。要不就用fastapplication安装试试,如果有比如某个程序和pyqt4有冲突,可能会帮你自动移除那个有冲突的软件。到时候你注意一下吧,实在不行就刷机。
安装PtQt4前你需准备:Xcode (10.6.1 自带Xcode)
Qt - 我使用的是qt-mac-cocoa-opensource-4.6.2.dmg
SIP - 我使用的是sip-4.12.1.tar.gz
PyQt4 - 我使用的是PyQt-mac-gpl-snapshot-4.8.4.tar.gz
创建了一个pyqt文件夹在硬盘根目录下,并将sip-4.12.1.tar.gz和PyQt-mac-gpl-snapshot-4.8.4.tar.gz
放到其中并解压。
1。先安装qt,默认安装,这一步大部分人不会有问题,跳过。
2。接下来,打开终端(Terminal,在 Applications(应用程序)/Utilities(实用工具)/ 下),在终端输入:export VERSIONER_PYTHON_PREFER_32_BIT=yes。
3.
使用"cd 路径"命令将当前目录设为sip-4.12.1,如: cd /pyqt/sip-4.12.1/, 然后进行配置(configure)【Re-build SIP in 32bit 】在终端中执行
python configure.py --arch i386
配置(configure)完成后就开始编译,在终端中执行引用make clean(清除以前的安装信息)make
编译完成后就安装,在终端中执行引用sudo make install
在这个过程中没出现错误就是安装成功了
编译安装PyQt4,过程和上面的一样。 【Build PyQt4 in 32bit 】
在终端中使用"cd 路径"命令将当前目录设为PyQt-mac-gpl-snapshot-4.8.4,如
引用cd /Users/schi/pyqt/PyQt-mac-gpl-snapshot-4.8.4
然后进行配置(configure),在终端中执行引用python configure.py --use-arch i386
配置时会遇到引用Determining the layout of your Qt installation...
This is the GPL version of PyQt 4.6 (licensed under the GNU General Public
License) for Python 2.6.2 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,再按回车就行
配置(configure)完成后就开始编译,在终端中执行
引用make cleanmake
编译比较花时间,请耐心等待。
编译完成后就安装,在终端中执行
引用sudo make install
在这个过程中没出现错误就是安装成功了
也可以在IDLE中导入PyQt4的模块,能成功导入就说明安装成功
Python代码
from PyQt4 import QtCore, QtGui
下面分析一下安装过程中可能遇到的问题:
1.问题如下
##############
ld: warning: in /Library/Frameworks/Python.framework/Python, missing required architecture x86_64 in file
Undefined symbols:
"_Py_Initialize", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyLong_AsVoidPtr", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyErr_Print", referenced from:
PyCustomWidgets::getModuleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::getModuleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyString_FromString", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyType_IsSubtype", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyModule_GetDict", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_CallObject", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_CallFunctionObjArgs", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyList_Append", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_Py_IsInitialized", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyDict_Next", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyImport_ImportModule", referenced from:
PyCustomWidgets::getModuleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_GetAttrString", referenced from:
PyCustomWidgets::getModuleAttr(char const*, char const*)in pluginloader.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: *** [libpythonplugin.dylib] Error 1
make: *** [all] Error 2
这个问题的原因就是:qt是在32位mac上编译的,但pyqt默认是在64位机子上编译的,所以我们在编译的时候要制定编译环境:是i386 还是x86_64.
请参考如下的信息:
The problem is that the Qt library is 32bit while, by default, python builds PyQt4 in 64bit. That caused problem when it tried to link 64bit object files with 32bit Qt library. To fix this issue, we need to force python to build PyQt4 in 32bit, and we also need to re-build SIP in 32bit mode. If you use the python version that comes with Mac OS (2.5 for Snow Leopard), make sure that it runs in 32bit mode by issuing the command
2.个问题如下:
>>>from PyQt4 import QtGui
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.6/site-packages/PyQt4/QtGui.so, 2): Symbol not found: __ZN13QPyTextObject16staticMetaObjectE
Referenced from: /Library/Python/2.6/site-packages/PyQt4/QtGui.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/PyQt4/QtGui.so
这个问题是所有的包安装都没有问题但是当导入QtGui或其他包时,总报这个问题,这个问题的原因是,当前pyqt release的包本身带的一个bug,PyQt-mac-gpl-snapshot-4.8.3, 所以你下载下个要release的包就可以了。如我下的是:PyQt-mac-gpl-snapshot-4.8.4。
下面给大家介绍一下我写的自动安装这些程序的python源码:
#!/usr/bin/env python
"""
Automated installer for Python 2.6 (final)
This installer is able to handle any previous
versions of Python.
NOTE: This file *must* be copied to
//nssgsvr/tools/pyInstall_OSX when modified!
"""
import os
import sys
import re
import shutil
import platform
import tarfile
# Constants
PYTHON_PKGS = {"dmgFile" : "python-2.6.1-macosx2008-12-06.dmg",
"mpkgList": ["MacPython.mpkg"] }
#WXPYTHON_PKGS = {"dmgFile" : "wxPython2.8-osx-unicode-2.8.9.2-universal-py2.6.dmg",
# "mpkgList": ["wxPython2.8-osx-unicode-universal-py2.6.pkg"] }
#ANGELIA
XCODE_PKGS = {"dmgFile" : None, "mpkgList": ["Xcode.mpkg"]}
QT_PKGS = {"dmgFile" : "qt-mac-cocoa-opensource-4.6.2.dmg",
"mpkgList": ["Qt.mpkg"] }
THIRD_PARTY_INSTALL = ["sip-4.12.1", "PyQt-mac-gpl-snapshot-4.8.4","Pyro-3.9.1", "pyserial-2.4"]
# Environment constants
TCSH_ENV_FILE = '/etc/csh.login'
BASH_ENV_FILE = '/etc/profile'
SCRIPTS_ROOT_ENV = "TEST_SCRIPTS_ROOT"
TARGET_VER = "2.6"
IS_POSIX = (os.name == 'posix')
IS_MAC = (sys.version.find('Apple') != -1)
IS_OSX = (IS_MAC and IS_POSIX)
IS_OSX_LEOPARD = (IS_OSX and platform.mac_ver()[0].startswith('10.5'))
IS_OSX_SNOWLEOPARD = (IS_OSX and platform.mac_ver()[0].startswith('10.6'))
# NSSGSVR Constants
MOUNT_POINT = "/Volumes/Test"
HOSTSERVER = "NSSGSVR.global.avidww.com" # Server that contains SQA scripts
SHARE = "TEST" # NSSGSVR share that contains the Python scripts directory
USER = "qatest"
PASSWD = "Cmqat/$/$/$" # slashes needed to escape special character '$'
pyqt还不错,它是Python语言的GUI编程解决方案之一。可以用来代替Python内置的Tkinter。其它替代者还有PyGTK、wxPython等优点:PyQt的API与Qt类似,Qt的文档通常仍然可以应用于PyQt。因此,PyQt的文档比PyGTK、wxPython、Tkinter等GUI编程库的文档丰富得多。如果程序员具备使用Qt的经验,一般很快就可以过渡到PyQt上。而使用PyQt的程序员,如果同时精通C++的话,也可以很快地过渡到Qt平台上。利用SIP,大多数为Qt开发的控件可以方便地port到PyQt。——然而,SIP也需要一些学习成本。有方便的周边工具支持PyQt。如QtDesigner,可以使用拖拉式的方法来设计界面,简单易用。Eric4,一个使用PyQt设计的PythonIDE,对PyQt有特殊的支持。缺点:由于PyQt同时使用Qt以及Python的两种内存管理方法,所以在使用PyQt的过程中要注意避免内存泄露以及悬挂指针[4]。运行时庞大,在Windows平台,只使用PyQt.QtCore与PyQt.QtGui两个子模块时,压缩后至少需要4.09M需要学习一些C++知识,主要是C++类型、内存管理两个方面,以便于阅读Qt文档和理解PyQt的行为欢迎分享,转载请注明来源:内存溢出
评论列表(0条)