Here are seven examples, of roughly increasing complexity, that demonstrate how to package python applications using the basic commands of PyInstaller. The later examples also demonstrate how to package a basic Kivy GUI app.
We recommend that this code is run inside a virtual environment.
- Linux or macOS (Tested on Ubuntu 14.04 and High Sierra)
- Python (Tested on Python 2.7 and 3.4)
- PyInstaller
- Numpy (To test non-standard library imports)
- Pandas (To process a csv file)
- Cython (Kivy dependency)
- Kivy (For apps 6 & 7, Tested on v1.10.1)
pip install pyinstaller
pip install numpy
pip install pandas
pip install cython
pip install kivy
- Download this repository
- Install the requirements
- Navigate to the app folder
- Have a look at the files inside the app folder to see what they do
- The examples are all kept very short and basic
- Run the corresponding PyInstaller command
- see 'Apps' section below
- Have a look at the folders and files that are created
- see 'Expected output' section below
- Try running the app
- The application is found inside the newly created
dist
folder
- The application is found inside the newly created
- Reset the folder
rm -r build/ & rm -r dist/ & rm *.spec
pyinstaller --name app_1 main.py
pyinstaller --onefile --name app_2 main.py
pyinstaller --onefile --add-data="MOCK_DATA.csv:." --name app_3 main.py
pyinstaller --onefile --add-data "data:data" --name app_4 main.py
pyinstaller --onefile --name app_5 main.py
pyinstaller --onefile --add-data="style.kv:." --name app_6 main.py
The commands above produce two folders and a .spec
file:
- The
build
folder contains temporary files that were used whilst the application was being built - The
dist
folder contains the application itself, which can now be distributed to other users - The
.spec
file tells PyInstaller how to process your script (see reference 2 for further info)
The application can be found inside the dist
folder, it can be run from the terminal using ./app_<num>
At run-time, the app will create a temporary folder to store data and binary files. The path to this folder can be accessed by the environment variable _MEIPASS
(only at run-time).