xcode 如何在 IOS Swift 应用程序中运行 python 程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46657162/
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 10:21:11  来源:igfitidea点击:

How to run python program in IOS Swift app

pythoniosswiftxcode

提问by Aaron Mednick

I'm an amateur coder working on a project right now, and I was wondering if you could help me.

我是一名业余编码员,现在正在从事一个项目,我想知道您是否可以帮助我。

Basically, I've been doing a lot of research on a particular algorithm that I find runs much faster using Python. The goal is to get this Python code to run in my IOS application. What I've found is that the Python interpreter has to be embedded with the Swift application in order to do this. However, I haven't found much useful documentation or other sources on how to do this. Do you have any suggestions or advice?

基本上,我一直在对我发现使用 Python 运行得更快的特定算法进行大量研究。目标是让这个 Python 代码在我的 IOS 应用程序中运行。我发现 Python 解释器必须嵌入到 Swift 应用程序中才能做到这一点。但是,我还没有找到太多有用的文档或其他有关如何执行此操作的资源。你有什么建议或意见吗?

回答by Max von Hippel

This tutorialseems to be fairly clear and easy to follow, and cover the necessary steps. Is there any chance you could share what the algorithm in question is? It might make more sense to use C - it looks like you can mix Obj-C with Swift. That said, I am not confident that you can actually do this on iOS.

本教程似乎相当清晰易懂,并涵盖了必要的步骤。您是否有机会分享所讨论的算法是什么?使用 C 可能更有意义 -看起来您可以将 Obj-C 与 Swift 混合使用也就是说,我不相信你真的可以在 iOS 上做到这一点。

First of all, your app might not get through App Store reviewif it has an executable for Python in it. Apple has its own docson embedding Python in OSX/Mac OS apps, but not for iOS.

首先,如果您的应用程序中有 Python 的可执行文件,则它可能无法通过 App Store 审核。Apple 有自己的关于在 OSX/Mac OS 应用程序中嵌入 Python的文档,但不适用于 iOS。

Additionally, I don't think an official executable of Python for iOS even exists. The closest thing I could think of, or find, is Pythonista, but I believe the developer made their own version of Python for iOS.

此外,我认为甚至不存在适用于 iOS 的 Python 官方可执行文件。我能想到或找到的最接近的东西是Pythonista,但我相信开发人员为 iOS 制作了他们自己的 Python 版本。

It looks like you can exportPythonista code to stand-alone apps, although how useful this is, and weather or not you can do this for iOS, I don't know. Additionally, that feature only works with Python2. Hope this helps.

看起来您可以Pythonista 代码导出到独立应用程序,尽管这有多大用处,无论天气与否,您是否可以为 iOS 执行此操作,我不知道。此外,该功能仅适用于 Python2。希望这可以帮助。