- PyByte
- Posts
- 👉 Convert your Python scripts into shareable programs
👉 Convert your Python scripts into shareable programs
Is this the worlds best Python newsletter?
from PyByte import deep_dive, get_inspired, byte_break
# Welcome to the PyByte!
👋 Hello coders! Elevate your Python knowledge with this week's PyByte. FYI there are only 60 days left in the year.
deep_dive()
This weeks Python trick comes from reel yours truly posted this last week that received a lot of interest.
In it I show how to convert Python scripts (.py or ipynb) to executables (.exe or unix executable).
If you’re interested, here’s the link to the reel. Let’s dive deeper into that concept, because it is a game-changer for creating your own shareable programs.
Here’s how it works: PyInstaller bundles a Python application and all the programs dependencies into a single package.
Open your command line interface (CLI) and install PyInstaller.
pip install pyinstaller
Now, return to your CLI and execute the command to create an executable from your Python script.
First, navigate to the directory containing your script.
Then run the following command:
pyinstaller --onefile your_script_here.py
This will generate a couple of files and folders in the current folder you are in.
Open the dist folder and you will see an .exe (Windows) or Unix Executable (Mac) with your Python script name (your_script_here.exe).

Try running it to see if it worked!
Things to know:
You cannot cross-compile. ie. the OS you build your executable on is the OS you can run it on (Mac for Mac, Windows for Windows).
Running this program will open a terminal/command line to run your program in. If you capture user input like
x = input(‘What is your name?’)
that will all happen inside that terminal.
PyInstaller should package all imported libraries in your executable. If you try running the generated program and it doesn’t work, it may have accidentally missed your packages.
To fix this you will manually instruct PyInstaller which libraries it should include.
Open your_script_here.spec, a generated file in the same folder as your Python file:

and edit the hiddenimports line:
a = Analysis(
...
hiddenimports=['pandas', 'openpyxl', ...etc],
...
)
Now, instead of running the above pyinstaller command you will generate the file based on the .spec file you just edited using the command:
pyinstaller your_script_here.spec
Open your dist folder again and you will see an updated program with all libraries imported.
get_inspired()
Imagine we’re sitting at your kitchen table, and I slide an envelope across the table.
You open it and in it is a check for $1,000,000,000.

Gif by iTrendz on Giphy
I then tell you there is only one caveat to accepting the money.
You wouldn’t wake up tomorrow.

Gif by abcnetwork on Giphy
What does your response reveal about the value of waking up tomorrow?
Waking up must be worth at least one billion dollars.
Watching this Dead Poets Society clip hit me hard this week.
If you want to go even deeper on the value of time, this Kurzgesagt video is an amazing visualization of an article called The Tail End.
Are you spending your time in the ways you want most?
👉This is the sign you’ve been looking for to carpe diem.
byte_break()
On the internet, nobody knows you’re a dog.
Oh, and one last thing…
I am not an Excel teacher, so if you’re looking to up your Excel game I want to introduce you to Miss Excel.

She is hosting a LIVE webinar next week where she will be teaching XLOOKUP and VLOOKUP (both extremely useful) and on top of that having a Q&A aftewards which she's never done before (in the webinars I’ve attended).
Sign up here!
Stay curious 👋
Joel