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?
Yes, you can run python code from swift by using the PythonKit, a framework based on the Python module from the Swift for TensorFlow project. It's important to note that Python is not available on iOS. But you can build pretty awesome utility apps for macOS and Linux.
iOS does not have Python pre-installed, so you'll have to embed a copy of Python within your app. Additionally, iOS apps can't run arbitrary secondary processes, so you'll have to run the Python interpreter inside your app's process.
Swift For TensorFlow supports Python interoperability. You can import Python modules from Swift, call Python functions, and convert values between Swift and Python.
This tutorial seems 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.
First of all, your app might not get through App Store review if it has an executable for Python in it. Apple has its own docs on embedding Python in OSX/Mac OS apps, but not for 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.
It looks like you can export Pythonista 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With