wxPython 2.7 dmg 中包含的 C 扩展模块似乎只有32 位。
$ cd /usr/local/lib/wxPython-unicode-2.8.11.0/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx
$ file *.so
_animate.so: Mach-O universal binary with 2 architectures
_animate.so (for architecture ppc): Mach-O bundle ppc
_animate.so (for architecture i386): Mach-O bundle i386
_aui.so: Mach-O universal binary with 2 architectures
_aui.so (for architecture ppc): Mach-O bundle ppc
_aui.so (for architecture i386): Mach-O bundle i386
...
不幸的是,platform.architecture()
它并没有准确指出 OS X 多架构 Python 正在哪个架构中运行。例如,使用 Python 2.7 的 3-arch python.org 安装程序,platform.architecture()
即使在 32 位模式下运行,也始终报告 64 位:
$ cd /Library/Frameworks/Python.framework/Versions/2.7
$ file python2.7
python2.7: Mach-O universal binary with 3 architectures
python2.7 (for architecture i386): Mach-O executable i386
python2.7 (for architecture ppc7400): Mach-O executable ppc
python2.7 (for architecture x86_64): Mach-O 64-bit executable x86_64
$ arch -x86_64 ./python2.7 -c 'import platform, sys; print "{0}, {1:x}".format(platform.architecture()[0], sys.maxint)'
64bit, 7fffffffffffffff
$ arch -i386 ./python2.7 -c 'import platform, sys; print "{0}, {1:x}".format(platform.architecture()[0], sys.maxint)'
64bit, 7fffffff
$ arch -ppc ./python2.7 -c 'import platform, sys; print "{0}, {1:x}".format(platform.architecture()[0], sys.maxint)'
64bit, 7fffffff
可靠的方法是检查sys.maxint
Python 2 或sys.maxsize
Python 3。
您没有在问题中说明如何调用 Python。是通过脚本文件中的 shebang 行吗?如果是这样,您可能没有运行您认为的 Python。此外,您没有指明您安装了哪个 Python 2.7。例如,python.org 目前有两个 Python 2.7 安装程序:一个支持 32 位和 64 位执行,另一个仅支持 32 位。尝试以下操作:
$ file $(python2.7 -c 'import sys;print(sys.executable)')
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: Mach-O universal binary with 3 architectures
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python (for architecture i386): Mach-O executable i386
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python (for architecture ppc7400): Mach-O executable ppc
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python (for architecture x86_64): Mach-O 64-bit executable x86_64
所以:如果你有 Python 的多架构版本,你需要强制它以 32 位模式运行以使用预编译的 wxPython。