How to package compiled Numba code?

I have to deliver a Python package containing compiled Numba code with just one performance critical function. It will be run on Android and iOS, where allegedly JIT is not allowed. I’ve never packaged a Python module before, so forgive me any fuzziness of this question.

I’m looking for a simple way to accomplish it. So far the best option I see is to use Nuitka: GitHub - Nuitka/Nuitka: Nuitka is a Python compiler written in Python. It's fully compatible with Python 2.6, 2.7, 3.4-3.13. You feed it your Python app, it does a lot of clever things, and spits out an executable or extension module. to create a wheel. I have not tried it yet, though, since I don’t have the required setup ready. Are there other options, perhaps easier?

Okay, prefacing my post with the fact that I know nothing on this topic, but nobody else has posted a solution… What’s the gap between your goals and this?

People who are deploying the app to Play Store (Android app store) are telling me that JIT is not allowed, therefore Numba functions, which are compiled on the first call are not allowed.

Can you put the cached compiled function into the package? I routinely do that with wheels targeting Linux.

Regular python normally generates bytecode into pycache directories… Is that also disabled on Android?

Hi, I’m the maintainer of Python’s Android support, and the Chaquopy project that’s built on top of it.

There are restrictions on JITs on iOS, which is why all iOS browsers have to use Apple’s JavaScript engine. But I’m not aware of any similar issues on Android. Can you provide more information?

I compiled Numba for Android back in 2020, and it can be built into any Android app using Chaquopy. I’ve tested it with each new Android version, and it’s worked with all of them so far.

Having said that, obviously it’s years out of date now, and only available for Python 3.8. I’m currently working on adding Android support to cibuildwheel; once that’s done, I’ll be submitting PRs to Numba and other projects to get official Android wheels on PyPI.

1 Like

Thanks for responding. I’m not familiar with details on Android, but the requirement is that the same Python code works on both iOS and Android. So, iOS may be the bigger problem of these two.

Yes, but Numba compiles to binary not the bytecode. There was a solution called pycc, but it’s now deprecated.