paddyg wrote: ↑
Sat Aug 22, 2020 7:15 am
On the other hand cython and numba, which are not mentioned, have been very fast - faster than my C on occasion. But they still need to be run using python and the code generally needs to be converted quite a bit.
Cython can and does create standalone native executables as described earlier; it is entirely the same as compiling any C program after conversion.
True, unrolling Python code to its C equivalent is quite complicated, and it does depend on linking other libraries during compilation, but that's not unusual. However complicated that is; it is largely irrelevant to those who simply want to turn Python source into native executable code.
I have not had to tweak any of my Python code to get it to compile via Cython but I may have just been lucky.
As to how much of the Python installation linked in during compilation needs to be provided for a distributed compile app to run I haven't been able to determine yet as all my Pi's have it all installed. When compiling for oneself that's mostly an irrelevancy.
I am sure there may be some caveats such as not supporting all the Python language constructs, but I haven't encountered any so far. The apt supplied Cython 3 package doesn't handle Python 3.8 or 3.9 additional syntax, but neither does Thonny or the Python 3.7 which is installed on a Pi by default.
As to any extensive run-time support required; that has never worried me. Code is doing the same whether that is done within the app or supplied by libraries. There's little difference except for what libraries may need to be distributed with the app or installed as dependencies. A suitable installation script will sort that out for end-users if distributing the app.
I'm not sure why there's so much negativity whenever compiling Python gets discussed, here or elsewhere, from 'it can't be done', to 'it won't work', 'won't work well', or 'won't deliver useful improvements'. It seems to me to mostly be discouragement from those who wouldn't do it that way, don't want to see others doing it that way.
I would suggest people try it and see how they get on, judge for themselves.