Call Python code from an existing project written in Swift
If anyone is ever interested in calling python from swift, here is some helpful material I found:
- U the python framework - https://developer.apple.com/library/ios/technotes/tn2328/_index.html
- PyObjC (a little more challenging) -
- Cobbal - https://github.com/cobbal/python-for-iphone
- Python docs (you would need to make C-Swift bridge)
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
Import Python code and library in Swift
Best bet is probably going to be the python framework: https://developer.apple.com/library/ios/technotes/tn2328/_index.html
Also check this out, very similar to your question: How to call Python code from an existing iOS project written in Swift
Swift receive string and run it in Python
there are several ways to do that .
You can invoke the system interpreter subprocess.run(...)
with option -c
and pass the commands as string.
You can also save the string to a file and execute it with the system interpreter.
I can't use Python module in Swift
A year later, I got a solution.
The name of module was wrong.
import PythonKit
let np = Python.import("numpy")
I should have installed on this way and implemented this way exactly.
Thanks regards!
Xcode: 11.3.1
Swift: 4.2
Toolchain: Swift for TensorFlow 0.8 Release
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)
If anyone is ever interested in calling python from swift, here is some helpful material I found(used) -
- use the python framework - https://developer.apple.com/library/ios/technotes/tn2328/_index.html
- PyObjC (a little more challenging) -
- cobbal - https://github.com/cobbal/python-for-iphone
- python docs (you would need to make C-Swift bridhe)
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
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.
Hope this will be helpful for anyone interested :-)
Related Topics
Transpose/Unzip Function (Inverse of Zip)
Find the First Instance of a Nonzero Number in a List in Python
How to Add Incremental Numbers to a New Column Using Pandas
Why Do People Write #!/Usr/Bin/Env Python on the First Line of a Python Script
What's the Pythonic Way to Use Getters and Setters
How to Watch a File For Changes
Getting Key With Maximum Value in Dictionary
Convert Rgb Color to English Color Name, Like 'Green' With Python
How to Terminate a Python Subprocess Launched With Shell=True
How to Control the Source Ip Address of a Zeromq Packet on a Machine With Multiple Ips
How to Use 'Subprocess' Command With Pipes
Imagemagick Not Authorized to Convert Pdf to an Image
MySQL_Config Not Found When Installing MySQLdb Python Interface
Unicodedecodeerror: 'Utf8' Codec Can't Decode Byte 0X9C
Take a Screenshot Via a Python Script on Linux
Indentationerror: Unindent Does Not Match Any Outer Indentation Level
Is False == 0 and True == 1 an Implementation Detail or Is It Guaranteed by the Language