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)

Shaun picture Shaun · Aug 12, 2015 · Viewed 11k times · Source

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

Answer

Shaun picture Shaun · Aug 14, 2015

If anyone is ever interested in calling python from swift, here is some helpful material I found(used) -

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