Bundling python apps with Nuitka in Haiku

This is most probably a corner case for app development in Haiku, but i want to say that you can pack a python application inside a single binary with this lib.

Infoworld article about Nuitka

If you want to install the library, just use pip and make sure you have the python dev package for your favourite version of python (2.x, 3.x) and run:

pip install Nuitka

It wont work “as is”, but will if you tweak the file:

/system/non-packaged/lib/python2.7/site-packages/nuitka/build/SingleExe.scons

And include the line around line 1027 of the file, for python 2.7:

python_header_path = "/system/develop/headers/python2.7/"

All the instructions available in the manual seem to work:

Nuitka Manual

I have been doing some tests on simple helloworld-apps and others than are a bit more complex with success, but as with all this compilers, your mileage may vary.

Running times didnt get faster than running the interpreter itself, but still have the feature of having a single “distributable” binary

2 Likes

“pip install --user” would be preferred.

Agreed, but in systems where the user has no priviledges and… it’s not the case for “user”, isnt it?
Wouldnt be found at the path i posted for tweaking in that case too :thinking:.

Anyway, this is just useful for distributing to a system without the modules you’r working with installed, which
is going to be a very low chance of happening (that’s more common in Windows world).

Thanks for the tip. I have used nuitka before on macos, but couldn’t get it to work on Haiku until now. On my old Mac, pystone runs at double speed when compiled with nuitka. So, depending on the kind of python application, it could indeed make a difference in terms of performance.

1 Like

Good day,

This topic is old, I know, but instead of start a new topic with the “same” intentions, I rather not duplicate things, to keep some sense of order.

Well, I’ve been searching for ways of doing things on Haiku with Python and decided to try Nuitka, which is, as @Pahefu said, a system to pack a python app into a binary that is executable, thus can have its own icon and attributes, even on the deskbar instead of the PythonX.Y icon.

The indication provided by @Pahefu might be good for old versions of Nuitka, as I wasn’t able to succeed with his notes, no such file inside new Nuitka. I digged and digged and found the new issue.

What I did was:
1- install Python 3.8 from HaikuDepot

2- install PyQt5 and PyQt5-Python3.8 [that’s the reason for installing Python 3.8?] from HaikuDepot in order to create some GUI apps [the Haiku Python API is a harder task to achive… maybe later will get enough courage to start to face it]

3- checking Nuitka’s requirements, it needs a C compiler [GCC or Clang], Haiku has already GCC, so nothing here; and also SCons, so installed Scons from HaikuDepot

4- created a testing folder ‘testing’, inside created a python environment ‘python3.8 -m venv penv --system-site-packages’ in order to have PyQt5 in the environment. Never succeeded to install PyQt5 with ‘pip’. Updated pip, and created a simple PyQt5 file, ‘test.py’ [just a plain PyQt widget].

5- inside the python environment [Terminal] installed nuitka ‘python -m pip install nuitka’ which installed without issues.

6- tested the python file inside the environment certifying it works. Then call [inside the environment] call ‘python -m nuitka test.py’ and wait.
The first time I did it it complained that could not find the Python.h header file inside /boot/system/include/Python3.8. Neither could I, so was going to ask for help in this forum when the topic by @pahefu came up. Tried his approach, didn’t work. So digging found the file, ‘Backend.scons’, inside the environment ‘penv/non-packaged/lib/python3.8/site-packages/nuitka/build/Backend.scons’. There in the method ‘_detectPythonHeaderPath’ added a candidate path [hardcoded]: ‘/system/develop/headers/python3.8’ and rerun ‘python -m nuitka test.py’. This time success:

nuitka

It’s a simple test of course. Now need more testing and with some proper applications.

Anyway, spent so much time doing research to end up finding an old topic here. In the end, it turns out that Nuitka’s requirements are easy to fulfill and might be a good option to package python apps [PyQt at the moment] for Haiku.

In the screenshot the executable is called ‘test.bin’, but the ‘.bin’ can be removed, of course.
Terminal shows the Error at the top ‘dependency not satisfied’ before I found the Backend.scons issue. No icon on the deskbar yet.

Hope you find this useful. I’ll have to get my fingers in shape to start doing some serious learning.

Regards,
RR

7 Likes

Good day,

Just tested with a simple, single file, Qt program, a calendar app:

CalendarNuitka

Two instances running, one from the Python 3.8 environment and the other built from Nuitka.

I tried a more complex program but I’m running Haiku virtualized inside Haiku to do the testing and it’s damn slow, and not sure if I have issues with QEMU, or what, because I get the VM window stalled quite often. I need to do the testing on bare metal and check again. Or run virtualized Haiku inside other OS to get performance improvements.

Nonetheless, for simple apps Nuikta is quite straightforward. We’ll see with bigger apps when I get a chance to test that on metal.

I also pushed a PR to the nuikta repo to add the Haiku path so only need to install nuitka through pip and good to go. Will report when it’s merged.

Regards,
RR

11 Likes

Good day,

Nuitka devs confirmed that the PR to include Python path abiding Haiku filesystem location has been merged, so hopefully the new Nuitka release will find the Python header without issues on Haiku. In the meantime we can get Nuitka’s code from Github and install it with the typical “python setup.py install”.

Hopefully, in the following days I’ll have time to test with bigger projects and report back.

Regards,
RR

3 Likes