简体   繁体   English

WxPython与Snow Leopard不兼容?

[英]WxPython Incompatible With Snow Leopard?

Recently I upgraded to Snow Leopard, and now I can't run programs built with wxPython. 最近我升级到Snow Leopard,现在我无法运行使用wxPython构建的程序。 The errors I get are (from Eclipse + PyDev): 我得到的错误是(来自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? 也许这与Snow Leopard是64位的事实有关?

Thanks!! 谢谢!!

The problem is that WxPython is only available on the Mac in 32-bit mode; 问题是WxPython仅在32位模式下在Mac上可用; however, by default, Python will start up in 64-bit mode. 但是,默认情况下,Python将以64位模式启动。 To fix this problem, create the following shell script named python_32 : 要解决此问题,请创建以下名为python_32 shell脚本:

#! /bin/bash
export VERSIONER_PYTHON_PREFER_32_BIT=yes
/usr/bin/python "$@"

Make the script executable ( chmod a+x python_32 ) and place the script in your path. 使脚本可执行( chmod a+x python_32 )并将脚本放在路径中。 Now, simply invoke python_32 to get an interactive Python console in which you can use WxPython. 现在,只需调用python_32即可获得一个交互式Python控制台,您可以在其中使用WxPython。 If you want to write a Python script that uses this, you can use the shebang: #! /usr/bin/env python_32 如果你想编写一个使用它的Python脚本,你可以使用shebang: #! /usr/bin/env python_32 #! /usr/bin/env python_32 . #! /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. 现在解释......基本问题是32位和64位代码使用不同的应用程序二进制接口(ABI),因此32位代码和64位代码不能共存于同一个库/可执行文件/进程中。 In order to support 64-bit mode, it needs to have been compiled in 64-bit mode; 为了支持64位模式,它需要在64位模式下编译; likewise, to support 32-bit mode, it needs to have been compiled in 32-bit mode. 同样,为了支持32位模式,它需要在32位模式下编译。 Under OS X, it is possible, using universal binaries to support both... however, it needs to be compiled in both modes (and then merged). 在OS X下,可以使用通用二进制文件来支持两者......但是,它需要在两种模式下编译(然后合并)。 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. WxWidgets可能使用Carbon,它只能在32位模式下使用(Cocoa可用于32位和64位模式...... Apple并不打算在两种模式下都使用Carbon,因为它已被弃用),这可以解释为什么WxPython反过来只能以32位模式提供。 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). 反过来,这意味着在Python中使用它需要您以32位模式启动Python(Python是一个通用二进制文件,其32位和64位版本本身可在同一个二进制文件中使用,因此它可以是以任一模式启动)。

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: 我不建议这样做,因为我认为您应该保留默认值,但是因为您可能没有足够的shell脚本知识(您需要使用“./python_32”或将其放在列出的文件夹中)您的“$ PATH”环境变量并将其调用为“python_32”)以遵循前一个选项,您可能只想执行以下命令,这将使32位模式成为默认值:

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

If you decide you want to switch back into 64-bit mode, you can then use the following command: 如果您决定要切换回64位模式,则可以使用以下命令:

defaults write com.apple.versioner.python Prefer-32-Bit -bool no

Note that both commands are to be executed on the Terminal (not within Python). 请注意,这两个命令都将在终端上执行(不在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. 我应该指出,两个推荐都是基于Mac OS X上的man python 。所以,如果你有任何其他问题,你一定要阅读手册页,因为错误信息已经催促你这样做了。

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. 2.9系列DOES具有Mac 64位版本,尽管仅适用于Python 2.7。 See http://wxpython.org/download.php and look for the Cocoa build. 请参阅http://wxpython.org/download.php并查找Cocoa构建。 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. 从我在wxPython邮件列表和IRC频道上收集到的内容,您将需要从python.org下载Python 64位版本,而不是使用包含Mac的蛇。

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. 您可能还想在调用python时尝试arch命令: arch -i386 /usr/bin/python2.6如果无法使用正确的环境设置运行Python。 The '-i386' switch makes a universal binary run in Intel 32-bit mode. '-i386'开关在Intel 32位模式下运行通用二进制。 '-x86_64' makes it run in Intel 64-bit mode. '-x86_64'使其在Intel 64位模式下运行。 -ppc and -ppc64 is for PPC architectures. -ppc和-ppc64用于PPC体系结构。

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. 在我的机器上,我有库存苹果Python和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). arch命令使用apple二进制文件,我可以从命令行成功导入wx但是我仍然从Macports二进制文件中得到错误: Bad CPU type in executable错误我猜我将不得不返回并重新编译我的Macports python二进制文件并确保它产生一个通用二进制或类似的东西(叹气)。

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. 另一个解决方案是从python.org下载并安装适用于OS X的Python 2.6,并从此处安装适用于OS X的wxPython。 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. python.org 2.6比Snow Leopard中Apple提供的Python(2.6.1)更新(目前为2.6.5),仅为32位。

This worked for me (from http://www.python-forum.de/viewtopic.php?f=19&t=24322&view=previous ) 这对我有用(来自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' 在.profile中,添加以下行别名py32 ='arch -i386 /Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7'

then invoke your script with py32 然后用py32调用你的脚本

Hm. 嗯。 The script provided didn't work for me-- I changed it as follows: 提供的脚本对我不起作用 - 我将其更改如下:

#! /bin/bash
echo "-----------------Python 2.6 - 32 Bit setup --------------------"
echo "Running" $1
export VERSIONER_PYTHON_PREFER_32_BIT yes
/usr/bin/python2.6 $1

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: 重新阅读手册页,以确保我没有误解,我没有进一步前进:

ImportError: /usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core_.so: no appropriate 64-bit architecture (see "man python" for running in 32-bit mode)

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. 不确定为什么这不起作用,除非需要对wx内核进行某种重建,以实现32/64位兼容性。 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 我想使用Apple的开箱即用的Python安装(对我的工作来说更容易),我想避免任何更荒谬的黑客攻击

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM