Table of Contents
← Go Back

Create Binary From Python Script

I wrote a script for this homelab-blog, so I don't have to edit the HTML and CSS all by myself. The script uses some keywords to know what kind of blog feature I want to use in my article. After writing the article in a simple TXT file with the keywords, it converts it to an HTML site with JavaScript for copying code blocks and CSS for some good looks.

But, I also want to use this on different machines where I don't have python installed, so a binary it must be.

image binary meme


Use PyInstaller

To "compile" my python script to a binary, I had to use a tool called "PyInstaller".

bash
1
2
3
4
5
# install PyInstaller
sudo pip install pyinstaller

# build binary file from my python script
pyinstaller --onefile html_converter.py

After that the finished binary file is located under /dist and can be run just like every other binary. I just also added it to my system's path, so I can use it system-wide.

bash
1
2
3
4
5
# add to system binary path
sudo cp html_converter /usr/local/bin/html_converter

# run binary
html_converter

XOR gitfeber