Compiling Python code

From PedrosBrainDump
Revision as of 21:52, 12 October 2024 by 413vhcu1lq0463ob (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Install the pyinstaller with pip

pip install pyinstaller

Use the pyinstaller to compile the binary

pyinstaller --onefile script.py

The binary will be on the dist directory.

Create your Python code:

sh-5.2$ cat main.py 
print('Hello, World!')
sh-5.2$ python3 main.py 
Hello, World!

Compile your code

sh-5.2$ pyinstaller --onefile main.py 

Run the binary

sh-5.2$ dist/main 
Hello, World!