Python compilation

From wikinotes
Revision as of 12:40, 21 October 2019 by Will (talk | contribs) (→‎cx_freeze)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

pyc files

pyc can be easily compiled or reverse-compiled.

python -m compileall -d "" /src/code_rootdir         # compile (-d hides orig path in tracebacks)
find /src/code_rootdir -name '*.py' -exec rm {} \;   # delete .py files

PyPy

I haven't had the opportunity to play with this yet, but pypy is supposed to be blindingly fast. Something to look out for.


cython

Cython expresses your python code as C/C++ code, then you use a compiler to compile it into a finished product. It boasts nearly 100% compatibility with python, and enables you to do further optimizations with static typing.

See python cython .

cx_freeze

The go-to low-level python freezing solution. Create standalones on linux, mac, windows for that operating system.

See python cx_freeze .

pyoxidizer

PyOxidizer is meant to create single file python executables. Supports mac, windows, linux.

See python pyoxidizer.

bbfreeze

bbfreeze is another compiler, but it's advantage is that it compiles to a format that runs on window,osx, AND linux.


WARNING:
bbfreeze is no longer maintained

Py2Exe

Compile python into executables on windows. currently python2.7 only.

See python py2exe.

pyinstall

A completely cross platform compiler. (Meaning it compiles linux binaries on linux, osx binaries on osx, windows binaries in windows). It prides itself on it's simplicity. I should look into this as a simpler alternative.