Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) [closed]

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

  • Short Question - is there any up-to-date PyObjC tutorial for embedding python scripts into an iOS app written 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.html Using the same method on iOS, it fails to compile

like image 389
Shaun Avatar asked Aug 12 '15 16:08

Shaun


People also ask

Can you use Python and Swift together?

Swift For TensorFlow supports Python interoperability. You can import Python modules from Swift, call Python functions, and convert values between Swift and Python.

Can I use Python in an iOS app?

Kivy is a Python framework that can be used to build both iOS and Android applications. Kivy is an open-source Python library that is used for the rapid development of applications that make use of innovative surfaces, such as multi-touch apps. It is 100% free to use.

Does Apple use Swift or Objective-C?

Most of the core iOS and MacOs software is still written in Objective-C, though Apple is pushing for new updates to be written in Swift.


1 Answers

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 :-)

like image 190
Shaun Avatar answered Sep 22 '22 12:09

Shaun