在iPhone应用程序中嵌入Python [英] Embedding Python in an iPhone app

查看:124
本文介绍了在iPhone应用程序中嵌入Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是一个新的千年;苹果挥了挥手;现在,将iPhone解释器包含在iPhone(App Store)应用程序中是合法的。

So it's a new millennium; Apple has waved their hand; it's now legal to include a Python interpreter in an iPhone (App Store) app.

如何做到这一点?所有现有的讨论(不出所料)都指的是越狱。 (旧问题:我可以使用Python编写原生iPhone应用程序

How does one go about doing this? All the existing discussion (unsurprisingly) refers to jailbreaking. (Older question: Can I write native iPhone apps using Python)

我的目标不是编写PyObjC应用程序,而是编写一个运行Python作为嵌入式库的常规ObjC应用程序。然后Python代码将回调本机Cocoa代码。它是控制逻辑是Python代码模式。

My goal here isn't to write a PyObjC app, but to write a regular ObjC app that runs Python as an embedded library. The Python code will then call back to native Cocoa code. It's the "control logic is Python code" pattern.

是否有指导在XCode中构建Python,以便我的iPhone应用程序可以链接它?最好是一个精简的Python,因为我不需要90%的标准库。

Is there a guide to getting Python built in XCode, so that my iPhone app can link it? Preferably a stripped-down Python, since I won't need 90% of the standard library.

我可以找出线程和Python扩展API;我在MacOS上做到了这一点。但是只使用命令行编译器,而不是XCode。

I can probably figure out the threading and Python-extension API; I've done that on MacOS. But only using command-line compilers, not XCode.

推荐答案

如何构建Python并不重要 - 你不要例如,不需要在Xcode中构建它 - 但重要的是该构建的产品。

It doesn't really matter how you build Python -- you don't need to build it in Xcode, for example -- but what does matter is the product of that build.

即,您需要构建类似的东西libPython.a可以静态链接到您的应用程序。一旦你有一个.a,就可以将它添加到你的应用程序的Xcode项目中,从那里,它将被链接和签名,就像你的应用程序的其余部分一样。

Namely, you are going to need to build something like libPython.a that can be statically linked into your application. Once you have a .a, that can be added to the Xcode project for your application(s) and, from there, it'll be linked and signed just like the rest of your app.

IIRC(自从我手工构建python已经有一段时间了)开箱即用的python将构建一个libPython.a(和一堆其他库),如果你配置它正确。

IIRC (it has been a while since I've built python by hand) the out-of-the-box python will build a libPython.a (and a bunch of other libraries), if you configure it correctly.

当然,你的第二个问题是从 86 框中为ARM交叉编译python。 Python是一个基于autoconf的项目,而autoconf对于交叉编译来说很痛苦。

Of course, your second issue is going to be cross-compiling python for ARM from your 86 box. Python is an autoconf based project and autoconf is a pain in the butt for cross-compilation.

正如你所说的那样,将它缩小至关重要。

As you correctly state, making it small will be critical.

也不奇怪,你不是第一个想要这样做的人,而不是iOS。 Python已被挤入设备中,而不是运行iOS的设备。在google搜索时,我发现了一个包含大量链接的帖子; 可能有用

Not surprising, either, is that you aren't the first person to want to do this, but not for iOS. Python has been squeezed into devices much less capable than those that run iOS. I found a thread with a bunch of links when googling about; it might be useful.

此外,您可能想加入 pyobjc-dev 列表。虽然你没有针对基于PyObjC的应用程序(顺便说一下,这是一个好主意 - PyObjC还有很长的路要走,它才会是iOS友好的),PyObjC社区一直在讨论这个和Ronald,任何人,可能是这个特定领域最知识渊博的人。请注意,在移植PyObjC之前,PyObjC必须解决嵌入式Python on iOS问题。他们的先决条件是你的要求。

Also, you might want to join the pyobjc-dev list. While you aren't targeting a PyObjC based application (which, btw, is a good idea -- PyObjC has a long way to go before it'll be iOS friendly), the PyObjC community has been discussing this and Ronald, of anyone, is probably the most knowledgeable person in this particular area. Note that PyObjC will have to solve the embedded Python on iOS problem prior to porting PyObjC. Their prerequisite is your requirement, as it were.

这篇关于在iPhone应用程序中嵌入Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆