Skip to content

mitchell-dawson/PyInstaller_examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyInstaller (+Kivy) Examples

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.

Requirements

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

Running the Code

  1. Download this repository
  2. Install the requirements
  3. Navigate to the app folder
  4. Have a look at the files inside the app folder to see what they do
    • The examples are all kept very short and basic
  5. Run the corresponding PyInstaller command
    • see 'Apps' section below
  6. Have a look at the folders and files that are created
    • see 'Expected output' section below
  7. Try running the app
    • The application is found inside the newly created dist folder
  8. Reset the folder
    • rm -r build/ & rm -r dist/ & rm *.spec

Apps

App1 - Simplest app with standard import

pyinstaller --name app_1 main.py

App2 - Import a function from another script

pyinstaller --onefile --name app_2 main.py

App3 - Include a single data file

pyinstaller --onefile --add-data="MOCK_DATA.csv:." --name app_3 main.py

App4 - Include folders of data

pyinstaller --onefile --add-data "data:data" --name app_4 main.py

App5 - Simple single file Kivy app

pyinstaller --onefile --name app_5 main.py

App6 - Kivy app with a separate kv file

pyinstaller --onefile --add-data="style.kv:." --name app_6 main.py

Expected Outcomes

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>

Location of Data and Binaries

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).

References

  1. Useful Introduction video
  2. Spec files
  3. Including data with app
  4. Bundling data files using onefile
  5. Using onefile
  6. Including data with PyInstaller
  7. Basic Kivy App
  8. Builder kivy options
  9. CSV file generator 1
  10. CSV file generator 2

Author

Mitchell Dawson

About

Examples applications using PyInstaller

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages