Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Using C modules in Pythonista
-
Hi,
I saw somewhat similar discussion here, but not exactly the same.
On my jailbroken iPhone, I had setup a complete build environment incl. clang, iOS SDK, Python Dev files, etc. One of the nice things this allows me to do is to compile Python modules that rely on C code. As an example I chose greenlet, which was listed as one of the blacklisted modules in StaSH, exactly because of the C dependency.
When I run it in a Python installation outside of Pythonista, all works well:
iPhone-5s:/private/var/mobile/Containers/Shared/AppGroup/appid/Pythonista3/Documents root# uname -a Darwin iPhone-5s 18.7.0 Darwin Kernel Version 18.7.0: Mon Aug 19 22:24:08 PDT 2019; root:xnu-4903.272.1~1/RELEASE_ARM64_S5L8960X iPhone6,2 arm64 N53AP Darwin iPhone-5s:/private/var/mobile/Containers/Shared/AppGroup/appid/Pythonista3/Documents root# file ./site-packages-3/greenlet.so ./site-packages-3/greenlet.so: Mach-O 64-bit arm64 bundle, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL> iPhone-5s:/private/var/mobile/Containers/Shared/AppGroup/appid/Pythonista3/Documents root# python3 Python 3.7.3 (default, May 8 2019, 14:19:08) [Clang 10.0.1 (clang-1001.0.46.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import greenlet >>> dir(greenlet) ['GREENLET_USE_CONTEXT_VARS', 'GREENLET_USE_GC', 'GREENLET_USE_TRACING', 'GreenletExit', '_C_API', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '__version__', 'error', 'getcurrent', 'gettrace', 'greenlet', 'settrace'] >>> dir(greenlet.greenlet) ['GreenletExit', '__bool__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_stack_saved', 'dead', 'error', 'getcurrent', 'gettrace', 'gr_frame', 'parent', 'run', 'settrace', 'switch', 'throw']
However, I am not able to call the same module from within Pythonista. I have the
greenlet.so
file in mysite-packages-3
folder, alongside my other non-C modules that work just fine, but when I callimport greenlet
, all I get isModuleNotFoundError: No module named 'greenlet'
error.Since I am doing this experiment on a jailbroken iPhone, I don't think code signing is at fault here, but I even tried signing the .so with my Developer Certificate, which did not help.
So, my question: Is Pythonista hardcoded to ignore any .so modules and to look for .pyc and .py only? Do you have any other idea I could try to force Pythonista to load an arm64-compiled C module?