首先我打开wxpython的网站,下载了适合os x使用的包,装载、安装,一切都很顺利。
但是打开python,import wx的时候却报错了。
>>> import wx Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/__init__.py", line 45, in from wx._core import * File "/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 4, in import _core_ ImportError: /usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/_core_.so: no appropriate 64-bit architecture (see "man python" for running in 32-bit mode)
错误提示里让我们“man python”查看32位模式下运行的帮助。
64-BIT SUPPORT Versions 2.6 and 2.7 support 64-bit execution (which is on by default). Like the version of Python, the python command can select between 32 and 64-bit execution (when both are available). Use: % defaults write com.apple.versioner.python Prefer-32-Bit -bool yes to make 32-bit execution the user default (using `/Library/Preferences/com.apple.versioner.python' will set the system-wide default). The environment variable VERSIONER_PYTHON_PREFER_32_BIT can also be used (has precedence over the preference file): % export VERSIONER_PYTHON_PREFER_32_BIT=yes # Bourne-like shells or % setenv VERSIONER_PYTHON_PREFER_32_BIT yes # C-like shells Again, the preference setting and environmental variable applies to both python and pythonw.
很明确了。
我执行了
export VERSIONER_PYTHON_PREFER_32_BIT=yes
然后重新打开python
import wx
成功,可以使用了。
下面是个简单的测试
InternelpdeiMac:~ internelp$ python Python 2.7.5 (default, Aug 25 2013, 00:04:04) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import wx >>> app=wx.App() >>> win=wx.Frame(None,title="wxPython Window") >>> btn=wx.Button(win,label='Install wxPython') >>> win.Show() >>> app.MainLoop()
这篇文章还没有人留言,快来抢沙发吧。