将 python 嵌入到用 Objective-C/Swift/C/C++ 编写的 iOS (iphone) 应用程序中(我可以在 Xcode 中编译并连接到 iOS 的任何语言)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31970695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:40:03  来源:igfitidea点击:

Embed python in to iOS (iphone) app written in Objective-C/Swift/C/C++ (whatever language i can compile in Xcode and bridge to iOS)

pythoniosobjective-cxcodepyobjc

提问by Shaun

I Do Not Intend To Put The Project On The App Store

我不打算把这个项目放在 App Store 上

  • Short Question- is there any up-to-date PyObjC tutorial for embedding python scripts into an iOS appwritten in Objective-C and/or swift? If not if there any up-to-date method for achieving the same goal?

  • Background: I want to run a bunch python scripts in an objective-c ios app. I have tried a couple of things:

    1. I have tried using the python.framework, but i get a "could not build Python module" error. After googling for help, I realized that python.framework does not work on iOS - Run python scripts in iOS app

    2. PyObjC - For the sake of experimenting, I managed to get the generated *.plugin working on OS X. I followed this tutorial - https://pythonhosted.org/pyobjc/tutorials/embedded.htmlUsing the same method on iOS, it fails to compile

  • 简短的问题- 是否有任何最新的 PyObjC 教程可以将 python 脚本嵌入到用 Objective-C 和/或 swift 编写的iOS 应用程序中?如果没有,是否有任何最新的方法可以实现相同的目标?

  • 背景:我想在一个objective-c ios应用程序中运行一堆python脚本。我尝试了几件事:

    1. 我曾尝试使用 python.framework,但出现“无法构建 Python 模块”错误。在谷歌搜索帮助后,我意识到 python.framework 在 iOS 上不起作用 -在 iOS 应用程序中运行 python 脚本

    2. PyObjC - 为了试验,我设法让生成的 *.plugin 在 OS X 上工作。我按照本教程 - https://pythonhosted.org/pyobjc/tutorials/embedded.html在 iOS 上使用相同的方法,它无法编译

回答by Shaun

If anyone is ever interested in calling python from swift, here is some helpful material I found(used) -

如果有人对从 swift 调用 python 感兴趣,这里有一些我发现(使用)的有用材料 -

Most of it is for Objective-c, but if you need to use swift you can easily just create an ObjC-Swift bridge (super-super easy) - Lookup the apple docs

大部分是针对 Objective-c 的,但如果你需要使用 swift,你可以轻松地创建一个 ObjC-Swift 桥(超级超级简单) - 查找苹果文档

I managed to get the first two methods working on an OS X app, but I got some architecture errors for iOS(not important). I've pushed the project aside for now, I have a ton I need to get done.

我设法让前两种方法在 OS X 应用程序上运行,但我在 iOS 上遇到了一些架构错误(不重要)。我暂时搁置了这个项目,我有很多事情需要完成。

Hope this will be helpful for anyone interested :-)

希望这对任何有兴趣的人都有帮助:-)