在 OS X 10.11 El Capitan 上安裝 RIDE

由於 RIDE 要求 wxPython 特定的版本,加上 wxPython 安裝程式的格式老舊、沒有數位簽章、只有 32-bit 的版本等,因此 wxPython 的安裝會是 RIDE 安裝過程中最難搞定的部份。

官方文件提到 RIDE 綁定 wxPython 2.8.12.1 (with Unicode support):

RIDE’s GUI is implemented using wxPython toolkit. Only wxPython 2.8.12.1 with Unicode support is officially supported.

事實上在 OS X 上,除了 wxPython 2.8 之外,也支援 wxPython 2.9

try:
    import wxversion
    from wxversion import VersionError
    if sys.platform == 'darwin': # CAN NOT IMPORT IS_MAC AS THERE IS A wx IMPORT
        wxversion.select(['2.8', '2.9'])
    else:
        wxversion.select('2.8')
except ImportError:
    print """wxPython not found.

通常而言,只要從 SourceForge 下載 wxPython<VERSION>-osx-unicode-<VERSION>-py<PYTHON_VERSION>.dmg,並透過裡頭的 .pkg 安裝即可。但從 OS X 10.8 Mountain Lion 之後,事情開始變得複雜…

OS X 10.8 Mountain Lion 增加了 Getkeeper,由於 wxPython 的 .pkg 都沒有數位簽章 (unsinged),所以開啟 .pkg 時會還到下面的錯誤:(下面以 wxPython 2.9.5.0 為例)

install-ride-on-osx-10.11-el-capitan/pkg_damaged.png

有兩種方法可以遶過這個問題:

  • 暫時關閉 Gatekeeper,但不建議這麼做。

    Settings > Security & Privacy > Allow apps downloaded from: Anywhere

  • 透過 installer -pkg 來安裝。
    $ sudo installer -pkg /Volumes/wxPython2.9-osx-2.9.5.0-cocoa-py2.7/wxPython2.9-osx-cocoa-py2.7.pkg/ -target /
    installer: Package name is wxPython2.9-osx-cocoa-py2.7
    installer: Upgrading at base path /
    2015-10-19 11:20:53.768 installer[74676:3957424] Package /Volumes/wxPython2.9-osx-2.9.5.0-cocoa-py2.7/wxPython2.9-osx-cocoa-py2.7.pkg uses a deprecated pre-10.2 format (or uses a newer format but is invalid).
    installer: The upgrade was successful.

不過上述這兩種方法在 OS X 10.11 El Capitan 都行不通了。

$ sudo installer -pkg /Volumes/wxPython2.9-osx-2.9.5.0-cocoa-py2.7/wxPython2.9-osx-cocoa-py2.7.pkg/ -target /
installer: Package name is wxPython2.9-osx-cocoa-py2.7
installer: Installing at base path /
2015-10-19 11:27:48.417 installer[875:22541] Package /Volumes/wxPython2.9-osx-2.9.5.0-cocoa-py2.7/wxPython2.9-osx-cocoa-py2.7.pkg uses a deprecated pre-10.2 format (or uses a newer format but is invalid).
installer: The install failed (The Installer could not install the software because there was no software found to install.)

雖然 Homebrew 的 wxmac formula 曾支援過 wxPython 2.9.5.0,但因為 #16329 的關係,在 OS X 10.10 之後,編譯的過程會遇到下面的錯誤:(Apple 將舊的 WebKit.h 更名為 WebKitLegacy.h)

./src/osx/webview_webkit.mm:936:25: error: cannot initialize a variable of type 'WebBackForwardList *' with an rvalue of type 'WKBackForwardList *'
    WebBackForwardList* history = [m_webView backForwardList];
                        ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/osx/webview_webkit.mm:954:25: error: cannot initialize a variable of type 'WebBackForwardList *' with an rvalue of type 'WKBackForwardList *'
    WebBackForwardList* history = [m_webView backForwardList];
                        ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

所以只好下載 source code 稍做修改後再自行編譯安裝。

  1. 先安裝 Xcode,下載 wxPython-src-2.9.5.0.tar.bz2
  2. 解壓縮後,將 src/osx/webview_webkit.mm#include <WebKit/WebKit.h> 改成 #include <WebKit/WebKitLegacy.h>
  3. 按照 wxmac formula 的做法編譯安裝。
    $ cd wxPython-src-2.9.5.0
    $ PREFIX=/usr/local
    $ ./configure --prefix=$PREFIX --enable-shared --enable-monolithic --enable-unicode --enable-std_string --enable-display --with-opengl --with-osx_cocoa --with-libjpeg --with-libtiff --with-libpng --with-zlib --enable-dnd --enable-clipboard --enable-webkit --enable-svg --with-expat --with-macosx-version-min=10.11 --with-macosx-sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk --enable-universal_binary=i386,x86_64 --disable-precomp-headers
    $ sudo make install # 1
    
    $ cd wxPython  # 2
    $ sudo python setup.py build_ext WXPORT=osx_cocoa WX_CONFIG=$PREFIX/bin/wx-config UNICODE=1 INSTALL_MULTIVERSION=1 BUILD_GLCANVAS=1 BUILD_GIZMOS=1 BUILD_STC=1
    
    $ sudo python setup.py install WXPORT=osx_cocoa WX_CONFIG=$PREFIX/bin/wx-config UNICODE=1 INSTALL_MULTIVERSION=1 BUILD_GLCANVAS=1 BUILD_GIZMOS=1 BUILD_STC=1
    ...
    warning: wx_install: path file '/Library/Python/2.7/site-packages/wx-2.9.5-osx_cocoa.pth' not created # 3
    1 編譯安裝 wxWidgets。(這個步驟很花時間)
    2 安裝 wxPython。
    3 不知道為什麼有這個 warning,不過同一個目錄下有 wx.pth

簡單測試一下:

>>> import wx
>>>

更多細節請參考這裡

廣告

發表迴響

Please log in using one of these methods to post your comment:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s