559 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls 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
|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.
25 Aytoun Street