12

I am running Python 2.7 under Mac OS 10.6.4, and I just installed wxPython from the wxPython2.8-osx-unicode-2.8.11.0-universal-py2.7.dmg binary. I am getting a weird error on the import wx line in my Python scripts. FYI, I can import the wx module just fine from PyCrust. I don't really see what I have done wrong here. Could anyone please assist?

  File "prod_cons_wx.py", line 6, in <module>
    import wx 
  File "/usr/local/lib/wxPython-unicode-2.8.11.0/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/__init__.py", line 45, in <module>
    from wx._core import *
  File "/usr/local/lib/wxPython-unicode-2.8.11.0/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 4, in <module>
    import _core_
ImportError: dlopen(/usr/local/lib/wxPython-unicode-2.8.11.0/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/_core_.so, 2): no suitable image found.  Did find:
    /usr/local/lib/wxPython-unicode-2.8.11.0/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/_core_.so: no matching architecture in universal wrapper
4

5 回答 5

9

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.maxintPython 2 或sys.maxsizePython 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。

于 2010-08-31T08:50:38.347 回答
4

只是为了澄清“Ned Deily”的建议:使用arch -i386 python2.7 script.py 在 32 位模式下运行。 确切的命令行是arch -i386 python pywrap Spare.py。这将允许您运行 PyCrust(在 OSX 10.6.x 上以 32 位模式运行)。

于 2011-03-26T22:37:15.890 回答
2

32位系统有两个文件,python2.7-32和pythonw2.7-32。您可以使用这两个文件来运行您的脚本。

我将python链接到python2.7-32并将pythonw链接到pythonw2.7-32。我的脚本都运行良好。

你可以试试。

于 2011-06-25T10:12:59.050 回答
1

现在有一个支持 64 位 Cocoa 的开发版本,位于http://downloads.sourceforge.net/wxpython/wxPython2.9-osx-2.9.4.0-cocoa-py2.7.dmg在此页面上找到:http:// www.wxpython.org/download.php#stable

这对我有用。

于 2013-08-08T23:43:40.810 回答
0

你是如何在 Snow Leopard OSX (10.6) 系列上安装 python 的?你的 python 是为 64 位还是 32 位编译的。

尝试执行以下操作:

import platform
print platform.architecture()

检查二进制文件 (wxpython dmg) 是为 32 位还是 64 位编译的。您可能必须寻找与您的体系结构兼容的包,或者您可能必须在您的机器上从源代码编译。

我建议你使用macports。

  1. 从 macport.org 安装 macports
  2. sudo /opt/local/bin/port 安装 python27
  3. sudo /opt/local/bin/port 安装 python_select
  4. sudo /opt/local/python_select python27
  5. sudo /opt/local/bin/port install py27-wxpython

这应该适合你!

于 2010-08-31T07:53:34.290 回答