PyObjC + Xcode 3.2 +非苹果Python

发布于 2024-08-20 13:24:30 字数 1469 浏览 7 评论 0原文

我想开始尝试使用 PyObjC 开发一些简单的应用程序。我安装了 PyObjC 和 Xcode 模板。我知道 PyObjC 本身可以工作,因为我已经运行 此脚本 成功。当我尝试从 Cocoa-Python 应用程序模板创建项目并运行它时,出现此错误:

Traceback (most recent call last):
  File "main.py", line 10, in 
    import objc
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyObjC/objc/__init__.py", line 25, in 
    from _convenience import *
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyObjC/objc/_convenience.py", line 21, in 
    from itertools import imap
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/itertools.so, 2): no suitable image found.  Did find:
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/itertools.so: mach-o, but wrong architecture
2010-02-08 19:40:09.280 TestApplication[3229:a0f] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '/Users/icktoofay/Desktop/TestApplication/main.m:44 main() PyRun_SimpleFile failed with file '/Users/icktoofay/Desktop/TestApplication/build/Debug/TestApplication.app/Contents/Resources/main.py'.  See console for errors.'

当我尝试打开普通的 Python 提示符并导入 itertools 时,没有错误。我在 Mac OS X 10.6 Snow Leopard 上使用来自 MacPorts 的 Python 2.6.4。

我将不胜感激任何帮助。

I want to get started trying to develop a few simple applications with PyObjC. I installed PyObjC and the Xcode templates. I know that PyObjC itself works, since I've run this script successfully. When I tried to create a project from the Cocoa-Python Application template and ran it, I got this error:

Traceback (most recent call last):
  File "main.py", line 10, in 
    import objc
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyObjC/objc/__init__.py", line 25, in 
    from _convenience import *
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyObjC/objc/_convenience.py", line 21, in 
    from itertools import imap
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/itertools.so, 2): no suitable image found.  Did find:
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/itertools.so: mach-o, but wrong architecture
2010-02-08 19:40:09.280 TestApplication[3229:a0f] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '/Users/icktoofay/Desktop/TestApplication/main.m:44 main() PyRun_SimpleFile failed with file '/Users/icktoofay/Desktop/TestApplication/build/Debug/TestApplication.app/Contents/Resources/main.py'.  See console for errors.'

When I tried opening a normal Python prompt and importing itertools, there was no error. I'm using Python 2.6.4 from MacPorts on Mac OS X 10.6 Snow Leopard.

I'd appreciate any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩物 2024-08-27 13:24:30

您遇到了 32 位与 64 位问题。看来您正在使用从 MacPorts 安装的 Python 2.6,并且显然它不是通用(32 位/64 位)版本。您的应用程序以 64 位运行,而 Python 仅以 32 位运行,或者反之亦然。您可以使用 file 进行检查:

cd /opt/local/Library/Frameworks/Python.framework/Versions/2.6/
cd lib/python2.6/lib-dynload/
file itertools.so 
itertools.so: Mach-O universal binary with 2 architectures
itertools.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
itertools.so (for architecture i386):   Mach-O bundle i386

最简单的修复可能是重新安装 MacPorts Python 和您安装的其他软件包,如 PyObjC:

sudo port selfupdate
sudo port -u install python26 +universal ...

编辑:由于您报告 Python 是 64 位,所以问题那么几乎可以肯定是由于 Python PyObjC 项目的 Xcode 模板设置存在问题。启动代码可能正在加载Apple提供的通用Python解释器。您可以通过在 import objc 之前添加类似的内容来进行检查:

import sys
sys.stderr.write(sys.executable)

对于 MacPorts,应该是

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python

我对在 Xcode 下使用模板的来龙去脉不太熟悉,不知道可能会发生什么需要更改,我怀疑很多人将它们与 MacPorts Python 一起使用,尤其是在 10.6 下。

另一个想法是,Apple 提供的 Python 2.6.1 附带了已安装的 PyObjC 版本。也许使用它会更简单。或者不使用 Xcode 并使用 py2app 或其他解决方案来运行它。

You have a 32-bit vs 64-bit problem. It appears you are using a Python 2.6 installed from MacPorts and apparently it was not a universal (32-bit/64-bit) build. Either your app is running as 64-bit and the Python is only 32-bit or the reverse. You can check by using file:

cd /opt/local/Library/Frameworks/Python.framework/Versions/2.6/
cd lib/python2.6/lib-dynload/
file itertools.so 
itertools.so: Mach-O universal binary with 2 architectures
itertools.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
itertools.so (for architecture i386):   Mach-O bundle i386

The easiest fix is likely to re-install the MacPorts Python and the additional packages you installed like PyObjC:

sudo port selfupdate
sudo port -u install python26 +universal ...

EDIT: Since you report that the Python is 64-bit, the problem then is almost certainly due to a problem with the Xcode template setup for your Python PyObjC project. The startup code is probably loading the Apple-supplied Python interpreter which is universal. You can check by adding something like this prior to the import objc:

import sys
sys.stderr.write(sys.executable)

For MacPorts, it should be

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python

I'm not familiar enough with the ins-and-outs of using the templates under Xcode to know what might need to be changed and I doubt that many people use them with a MacPorts Python, especially under 10.6.

Another thought, the Apple-suppied Python 2.6.1 comes with a version of PyObjC already installed. Perhaps using it would be simpler. Or don't use Xcode and use py2app or another solution to run it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文