by std_throwaway · 8y ago · 0 comments
Edit: I'm aware that there are solutions that put everything a program touches into a kind of executable archive. A single file several hundred Megabytes in size. I've tested it. It doesn't really pre-compile the modules. The startup time was exactly the same.
- it compiles your program and make it stand alone so you can distribute just the exe
- it makes it start faster
- it makes it run faster
- it's fully independant of the system python. Actually your system doesn't even need a python at all
I don't get why it's not used, it's very robust, compatible with 3.6 and on some of my script I get about x4 speed up just on start up alone.
Is Nuikta compatible with numpy, pickle, etc? I remember that numpy was very problematic with compilers like pypy for a long time.
Nuikta supports numpy officially, you can even see it in change logs: http://nuitka.net/posts/nuitka-release-0521.html
I haven't tried pickle.
In an ancestor comment you say:
> A single file several hundred Megabytes in size.
Are both points referring to PyInstaller? Asking because I've tried out PyInstaller with small CLI as well as GUI (wxPython) programs, and the resulting EXEs did not reach near that size, IIRC.
Any time I see something like this, I feel like I'm hearing about some homeopathic cancer cure. If Nuitka actually does what it says it does, it's solving a big recurrent problem for the Python community, so why is nobody talking about it?
- Before Nuitka, someone already did a "Python->C" compiler along similar lines: translate the Python source code into the C calls that the interpreter will make, eliminating any interpreter overhead and providing C compiler optimization opporunities. That thing sort-of-worked (with v1.5.2 IIRC), but was cumbersome to use and delivered a meager 5% performance improvement for the cases it did support; it was abandoned.
- Nuitka's plan had the same thing as a starting phase; people told the Nuitka guy that he's wasting his time based on prior experience. When he actually delivered a mostly-robust working version (much more usable than the previous attempts ever were), it indeed delivered only a small performance gain compared to CPython.
- As a result, it seemed like the community believed both that the whole thing is futile, and that the developer is fighting windmills.
- a lot of time passes, Nuitka keeps improving with better analysis, translation, compilation, etc - but the community has already cemented its opinion.
- Nuitka remains a useful magic system known to few.
I would say that the early Nuitka versions (and the prior attempt) gave it a SEP field that has never been lifted, and short of e.g. DropBox or Facebook adopting it, nothing will lift it either.
That said, it's a wonderful project, I hope more and more people will find it useful for them.
Not only it's a beautiful tool, but the author has been quietly and steadily working on it for 8 years. Compatibility is the number one goal.
The guy has a lot of rigor and humility, so maybe communication suffered ?
I've learned not to try to talk about it because of that question: "If foo is so great, why isn't everybody using it?"
It's one of the single greatest frustrations of my life. I don't know. I've never made any progress on it. The best you can say is, "Well, that seems to be human nature." The world is full of "magic beans" and most people seem interested in banging their heads against the wall.
(Did you know, you can make a 140hp engine that fits in the volume of two stacked pizza boxes and has only one moving part?)
Anyhow, Nuitka is great, it does do all that.
And the creator is a freakin' saint for putting up with the way he's been treated by the Python community, is my opinion.
Eg: after 7 years of having malaria, one tropical disease doctor explained to me that we have been able to cure malaria for years. Generalist doctors usually don't know it because they don't encounter the disease often enough to keep up to date. It's kind of hard pill to swallow given that i always though you had it for life.
$ echo 'print "Hello world"' > hello.py
$ nuitka --standalone hello.py
$ ldd hello.dist/hello.exe
linux-gate.so.1 (0xf7f94000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xf7895000)
libpython2.7.so.1.0 => /home/jwilk/hello.dist/libpython2.7.so.1.0 (0xf7508000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf732f000)
/lib/ld-linux.so.2 (0xf7f96000)
libz.so.1 => /home/jwilk/hello.dist/libz.so.1 (0xf7310000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xf72f1000)
libutil.so.1 => /home/jwilk/hello.dist/libutil.so.1 (0xf72ed000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xf71eb000)Cython is a complicated beast but I feel like it just needs a more friendly wrapper for this to be more widespread.
https://stackoverflow.com/questions/22507592/making-an-execu...
https://github.com/cython/cython/wiki/EmbeddingCython
Why Cython isn’t in the stdlib (I think it could easily replace ctypes) is beyond me sometimes
We were able to solve most of the problem by zipping up the Python standard library and the our application.
That is, if you look at sys.path you'll see something like:
>>> sys.path
['', '/usr/local/lib/python36.zip', '/usr/local/lib/python3.6', ...]
If you zip up the python3.6 directory into python36.zip then it will use that zip file as the source of the standard library, and use the zip directory structure instead of a bunch of stat calls to find the data.This should also include getting access to the pre-compiled byte code.
You can also have Python byte-compile all of the .py files in a directory as part of your build/zip process.
python -m compileall --help find . -type f -name "*.py" -delete
right afterwords.Also note calls to imp.load_source need to change to imp.load_compiled, and any .py files references directly in code need to be changed to .pyc (this is with 2.7, not sure about 3.x)
https://github.com/dart-lang/sdk/wiki/Snapshots
It's what Flutter uses on iOS since you can't run JITed code; AOT compile it and load it as just another shared library.