WxPython 与雪豹不兼容?
最近我升级到了 Snow Leopard,现在我无法运行用 wxPython 构建的程序。我得到的错误是(来自 Eclipse + PyDev):
import wx
File "/var/tmp/wxWidgets/wxWidgets-13~231/2.6/DSTROOT/System/Library/Frameworks
/Python.framework/Versions/2.6/Extras/lib/
python/wx-2.8-mac-unicode/wx/__init__.py", line 45, in <module>
File "/var/tmp/wxWidgets/wxWidgets-13~231/2.6/DSTROOT
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib
/python/wx-2.8-mac-unicode/wx/_core.py", line 4, in <module>
ImportError:/System/Library/Frameworks
/Python.framework/Versions/2.6/Extras/lib/python
/wx-2.8-mac-unicode/wx/_core_.so: no appropriate 64-bit architecture
(see "man python" for running in 32-bit mode)
我不太理解它们,如果您能帮助我这样做,我将不胜感激,而且,如果您确实知道发生了什么,我该如何修复它们?也许这与 Snow Leopard 是 64 位有关?
谢谢!!
Recently I upgraded to Snow Leopard, and now I can't run programs built with wxPython. The errors I get are (from Eclipse + PyDev):
import wx
File "/var/tmp/wxWidgets/wxWidgets-13~231/2.6/DSTROOT/System/Library/Frameworks
/Python.framework/Versions/2.6/Extras/lib/
python/wx-2.8-mac-unicode/wx/__init__.py", line 45, in <module>
File "/var/tmp/wxWidgets/wxWidgets-13~231/2.6/DSTROOT
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib
/python/wx-2.8-mac-unicode/wx/_core.py", line 4, in <module>
ImportError:/System/Library/Frameworks
/Python.framework/Versions/2.6/Extras/lib/python
/wx-2.8-mac-unicode/wx/_core_.so: no appropriate 64-bit architecture
(see "man python" for running in 32-bit mode)
I don't really understand them and would appreciate if you could help me to do so, also, if you do know what's going on, how can I go about fixing them? Maybe this has something to do with the fact that Snow Leopard is 64-bit?
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
问题是 WxPython 只能在 Mac 上以 32 位模式使用;但是,默认情况下,Python 将以 64 位模式启动。要解决此问题,请创建以下名为
python_32
的 shell 脚本:使脚本可执行 (
chmod a+x python_32
) 并将脚本放置在您的路径中。现在,只需调用python_32
即可获得一个交互式 Python 控制台,您可以在其中使用 WxPython。如果你想编写一个使用它的 Python 脚本,你可以使用 shebang:#! /usr/bin/env python_32
。现在解释一下...基本问题是 32 位和 64 位代码使用不同的应用程序二进制接口 (ABI),因此 32 位代码和 64 位代码不能共存于同一个库/可执行文件/进程中。为了支持64位模式,需要已经在64位模式下编译;同样,要支持 32 位模式,需要以 32 位模式编译。在 OS X 下,可以使用通用二进制文件来支持这两种模式...但是,它需要在两种模式下进行编译(然后合并)。 WxWidgets 可能使用 Carbon,它仅在 32 位模式下可用(Cocoa 在 32 位和 64 位模式下都可用...Apple 没有费心让 Carbon 在两种模式下都可用,因为它已被弃用),这可以解释为什么 WxPython 只能以 32 位模式提供。反过来,这意味着在 Python 中使用它需要您以 32 位模式启动 Python(Python 是通用二进制文件,在同一个二进制文件中可以使用其自身的 32 位和 64 位版本,因此可以以任一模式启动)。
替代选项
我不建议这样做,因为我认为您应该保留默认值,但由于您可能没有足够的 shell 脚本知识(您需要使用“./python_32”或将其放在列出的文件夹中您的“$PATH”环境变量并将其调用为“python_32”)要遵循前一个选项,您可能只想执行以下命令,这将使 32 位模式成为默认模式:
如果您决定要切换回 64 位 模式-bit 模式,然后您可以使用以下命令:
请注意,这两个命令都将在终端上执行(而不是在 Python 中)。
来源
我应该指出,这两个建议都是基于 man python。因此,如果您有任何其他问题,您一定应该阅读手册页,因为错误消息敦促您这样做。
The problem is that WxPython is only available on the Mac in 32-bit mode; however, by default, Python will start up in 64-bit mode. To fix this problem, create the following shell script named
python_32
:Make the script executable (
chmod a+x python_32
) and place the script in your path. Now, simply invokepython_32
to get an interactive Python console in which you can use WxPython. If you want to write a Python script that uses this, you can use the shebang:#! /usr/bin/env python_32
.Now to explain... the basic problem is that 32-bit and 64-bit code uses a different application binary interface (ABI), and so 32-bit code and 64-bit code cannot coexist in the same library/executable/process. In order to support 64-bit mode, it needs to have been compiled in 64-bit mode; likewise, to support 32-bit mode, it needs to have been compiled in 32-bit mode. Under OS X, it is possible, using universal binaries to support both... however, it needs to be compiled in both modes (and then merged). WxWidgets probably uses Carbon, which is only available in 32-bit mode (Cocoa is available in both 32-bit and 64-bit mode... Apple didn't bother making Carbon available in both modes, since it is being deprecated), which would explain why WxPython, in turn, could only be provided in 32-bit mode. This, in turn, means that using it in Python requires you to launch Python in 32-bit mode (Python is a universal binary with both 32-bit and 64-bit versions of itself available in the same binary file, so it can be launched in either mode).
Alternative Option
I don't recommend doing this, because I think you should leave the defaults as they are, but since you might not have enough shell scripting knowledge (you need to use "./python_32" or place it in a folder that is listed in your "$PATH" environment variable and invoke it as "python_32") to follow the former option, you might want to simply execute the following command which will make 32-bit mode the default:
If you decide you want to switch back into 64-bit mode, you can then use the following command:
Note that both commands are to be executed on the Terminal (not within Python).
Source
I should point out that both recomendations are based on man python on Mac OS X. So, if you have any other questions, you should definitely read the man page as the error message has urged you to do.
虽然我看到这个问题已经得到解答,但答案略有错误。 2.9 系列确实有 Mac 64 位版本,尽管仅适用于 Python 2.7。请参阅 http://wxpython.org/download.php 并查找 Cocoa 版本。根据我在 wxPython 邮件列表和 IRC 频道上收集的信息,您需要从 python.org 下载 Python 64 位版本,而不是使用 Mac 包含的 Snake。
While I see this is already answered, the answer is slightly wrong. The 2.9 series DOES have a Mac 64-bit build, albeit only for Python 2.7. See http://wxpython.org/download.php and look for the Cocoa build. From what I gather on the wxPython mailing list and IRC channel, you'll want to download a Python 64-bit build from python.org rather than using the Mac-included snake.
如果您无法让 Python 在正确的环境下运行,您可能还想在调用 python 时尝试 arch 命令:
arch -i386 /usr/bin/python2.6
设置。 “-i386”开关使通用二进制文件在 Intel 32 位模式下运行。 '-x86_64' 使其在 Intel 64 位模式下运行。 -ppc 和 -ppc64 用于 PPC 架构。如果仍然出现错误,则可能表明存在编译问题。在我的机器上,我有库存的苹果Python和Macports的版本。 arch 命令使用苹果二进制文件工作,我可以从命令行成功导入 wx,但我仍然从 Macports 二进制文件中收到错误:
可执行文件中的 CPU 类型错误
我猜我必须去返回并重新编译我的 Macports python 二进制文件,并确保它生成一个通用二进制文件或类似的东西(叹气)。You might also want to try arch command when invoking python:
arch -i386 /usr/bin/python2.6
if you can't get Python to run with the correct environmental settings. The '-i386' switch makes a universal binary run in Intel 32-bit mode. '-x86_64' makes it run in Intel 64-bit mode. -ppc and -ppc64 is for PPC architectures.If you still get errors then it might point to a compile issue. On my machine I have the stock apple Python and a version from Macports. The arch command works using the apple binaries and I can import wx successfully from the command line but I still get errors from the Macports binary:
Bad CPU type in executable
I'm guessing I'll have to go back and recompile my Macports python binary and make sure it produces a universal binary or something like that (sigh).另一个解决方案是从 python.org 下载并安装适用于 OS X 的 Python 2.6 并安装适用于 OS 的 wxPython X 来自此处。 python.org 2.6 比 Snow Leopard 中 Apple 提供的 Python (2.6.1) 更新,而且它只是 32 位。
Another solution is to download and install Python 2.6 for OS X from python.org and install wxPython for OS X from here with it. The python.org 2.6 is newer (2.6.5 as of now) than the Apple-supplied Python (2.6.1) in Snow Leopard and it is 32-bit only.
这对我有用(来自 http://www .python-forum.de/viewtopic.php?f=19&t=24322&view=previous)
在 .profile 中,添加以下行
alias py32='arch -i386 /Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7'
然后调用您的脚本
py32
This worked for me (from http://www.python-forum.de/viewtopic.php?f=19&t=24322&view=previous)
In .profile, add the following line
alias py32='arch -i386 /Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7'
then invoke your script with
py32
嗯。提供的脚本对我不起作用——我将其更改如下:
仍然不起作用。我收到同样的信息。重新阅读手册页以确保我没有误解,并且我不再继续前进:
不太确定为什么这不起作用,除非需要对 wx 核心进行某种重建赋予它 32/64 位兼容性。有什么建议吗?我想使用 Apple 提供的开箱即用的 Python 安装(对我的工作来说更容易),并且我想避免任何更荒谬的黑客行为
Hm. The script provided didn't work for me-- I changed it as follows:
Still didn't work. I get the same message. Re-read the man page to make sure I wasn't misunderstanding, and I'm no further forward:
Not really sure why this doesn't work, unless there is some sort of rebuild that needs to be done against the wx core that gives it 32/64-bit compatibility. Any suggestions, anyone? I'd like to use the out-of-the-box Python install from Apple (be easier for my work), and I'd like to avoid any more ridiculous hacks