I need a way to call Python code from Swift on an Apple platform. A library would be ideal. I've done a considerable amount of Google searching, and the closest material I found is for Objective-C.
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.
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. That's quite possible, but it involves a good understanding of the Python runtime.
In swift 5 you can try PythonKit framework.
Here's example of the usage:
import PythonKit let sys = try Python.import("sys") print("Python \(sys.version_info.major).\(sys.version_info.minor)") print("Python Version: \(sys.version)") print("Python Encoding: \(sys.getdefaultencoding().upper())")
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