Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
551 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Creating executable files from Python programs using pyinstaller |
---|
A summary of how to package up your Python program (including any referenced modules) into a single executable file. |
To package a program that you've created into a single executable file, the first thing that you need to do is to install the pyinstaller module. In Visual Studio Code, for example, you can do this by running the following command in the terminal window:
On my current version of VS Code this installed a lot of dependent modules too!
Installing Pyinstaller adds all of these other modules too.
You then need to write a program. I'm using one which displays this form:
My program displays a basic form, and counts the number of links in it.
For the above example, this would show the following at the time of writing:
The program counts the number of hyperlinks in the given webpage, and shows this number.
Please don't judge me on this program: I just wanted something quick to use for an executable, which imported at least one installed module (in this case requests). You can download the program here if you want to use it.
You can then go to the Visual Studio Code (or other) terminal window, change the directory to your folder and run the pyinstaller script:
Change your directory to the folder containing your Python program, then install it by running the command shown. The --onefile directive ensures you will get a single executable file.
This builds the following files and folders:
The installer has added 3 folders in my location: it's the dist one which contains the executable file.
You can now run your executable!
You can double-click on the file created to run it.
This will run on your computer even if you don't have Python or any of the modules installed. The only limitation is that you must run it on the same platform as you used to create the installation (be this Windows, Linux or Mac). You can see the full pyinstaller manual here.
Some other pages relevant to the above blog include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.