回覆列表
  • 1 # 使用者7258564354885

    安裝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 "$"

  • 中秋節和大豐收的關聯?
  • 在5G時代,之前建造的4G基站會變成一堆廢鐵嗎?