Tech/HowTo/Python Freeze
Jump to navigation
Jump to search
About
How to make a portable binary out of some Python code. Us Python Freeze which is part of the core Python Project
Requirements
Some Python packages put the freeze.py in the pythonX-examples package and you will also need the libz-dev package.
A library may need linked
ln -s /usr/lib/x86_64-linux-gnu/libpython3.9.so /usr/lib/libpython3.9.so
Example
Playing with my protocols package I gave it a try (I had to manually disable a call to __file__)
Normal:
python3 example.py NTP server serving on 127.0.0.1 at port 8123 Query NTP for time and report in ISO8601 format 2020-08-14 07:40:10 NTP server is currently Off
Compile and run as binary
mkdir tmp python3 /usr/share/doc/python3.9/examples/freeze/freeze.py -X codecs -X copy -X distutils -X encodings -X locale -X pydoc -X warnings -o tmp example.py -m protocols cd tmp make ./example NTP server serving on 127.0.0.1 at port 8123 Query NTP for time and report in ISO8601 format 2020-08-14 07:34:51 NTP server is currently Off