实现 PyObjc NsObject 子类
我有一个 Objc-C 项目,我希望能够通过 Python 处理一些数据。为此,我决定实现一个 PyObjc NSObject 子类,然后通过接口构建器将其链接到我的 Obj-C 类。
我将 Python 框架添加到我的项目中,并添加了一个包含以下简单代码的 python 文件:
import objc
from Foundation import *
from AppKit import *
class PythonWrapper(NSObject):
def applicationDidFinishLaunching_(self, sender):
NSLog("Application did finish launching.")
我在 XIB 中创建了一个 PythonWrapper 实例(构建器自动识别它的名称)。但是,在构建时,即使没有将其链接到其他类,我也会遇到以下问题:
忽略文件 /Developer/SDKs/MacOSX10.6.sdk/Library/Frameworks//Python.framework/Python,文件中缺少所需的架构 x86_64
此外,xCode 日志还显示:
未知类“PythonWrapper”,使用“NSObject”代替。在路径 /Users/joao/Library/Developer/Xcode/DerivedData/Jalioneiro-ekjwzbkqqgpyekadkyebhgdsjcxo/Build/Products/Debug/Jalioneiro.app/Contents/Resources/en.lproj/Interface.nib 的 Interface Builder 文件中遇到。
我在这里缺少什么?有没有其他方法可以将 python 代码链接到我的 Obj-C 类?
注意:我正在开发 xCode4
I have an Objc-C project in which I would like to be able to process some data trough Python. For that, I decided to implement a PyObjc NSObject subclass, which I would then link to my Obj-C classes trough the interface builder.
I added the Python framework to my project, and an python file with the following simple code:
import objc
from Foundation import *
from AppKit import *
class PythonWrapper(NSObject):
def applicationDidFinishLaunching_(self, sender):
NSLog("Application did finish launching.")
I created a PythonWrapper instance in my XIB (the builder automatically recognized the name of it). But, when building, even without having linked it already to the other classes, I get the following issue:
Ignoring file /Developer/SDKs/MacOSX10.6.sdk/Library/Frameworks//Python.framework/Python, missing required architecture x86_64 in file
Also, the xCode log also shows:
Unknown class 'PythonWrapper', using 'NSObject' instead. Encountered in Interface Builder file at path /Users/joao/Library/Developer/Xcode/DerivedData/Jalioneiro-ekjwzbkqqgpyekadkyebhgdsjcxo/Build/Products/Debug/Jalioneiro.app/Contents/Resources/en.lproj/Interface.nib.
What am I missing here? Is there any other way to link python code to my Obj-C classes?
Note: I'm working on xCode4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我听说 Xcode 4 与 PyObjC 的配合不太好,但我仍在使用 3,所以我不能确定。
您的第二个错误的原因(这也让我一直)是您需要将自定义类导入到项目的 main.py 中:
第一个错误看起来像您正在尝试构建仅限 64 位的应用程序。 Snow Leopard 附带的 PyObjC 仅编译为 32 位(实际上,我认为默认的 Python 也是如此)。尝试将 Target 的构建架构切换为 32 位或 32/64 位通用。您还可以沿着重新编译 PyObjC 并将其包含在您的应用程序包中的路径 - 我自己还没有尝试过。
I have heard that Xcode 4 does not play so nicely with PyObjC, but I'm still using 3, so I can't be sure.
The reason for your second error (and this bites me too all the time) is that you need to import your custom classes into your project's main.py:
The first error looks like you're trying to build a 64-bit-only application. The PyObjC that shipped with Snow Leopard is only compiled as 32-bit (actually, I think the same is true of the default Python). Try switching your Target's build architecture to either 32-bit or 32/64-bit Universal. You could also go down the path of re-compiling PyObjC and including it in your app's bundle -- haven't tried it myself.