How to package Python Project into a standalone executable?

28.5k views Asked by At

i wan't to release my python project, but when i send it to someone he is forced to install all the packages im using in my python project.

Is there any way to pack it or something, because maybe there are some users who are not that familiar with pip or python.

Regards

3

There are 3 answers

6
Dorian Turba On BEST ANSWER

PyInstaller

PyInstaller is a program that freezes (packages) Python programs into stand-alone executables, under Windows, GNU/Linux, Mac OS X, FreeBSD, Solaris and AIX. Its main advantages over similar tools are that PyInstaller works with Python 2.7 and 3.4—3.7, it builds smaller executables thanks to transparent compression, it is fully multi-platform, and use the OS support to load the dynamic libraries, thus ensuring full compatibility.

It work even if users do not have python installed.

Here an example from a github project. As you can see, you can download sources, but also a zip containing every package used to run your project. In this example, it contains many files, but you can package everything into a single .exe file.

How to use (Manual):

Install PyInstaller from PyPI:

pip install pyinstaller

Go to your program’s directory and run:

pyinstaller yourprogram.py

This will generate the bundle in a subdirectory called dist.

You can use --onefile argument in order to generate the bundle with only a single executable file.

Case specific:

You asked how to get arguments send by the user. Here is some way to do it, more or less convenient:

  • Use input(),
  • Use a config file,
  • Use default parameter.
1
SimbaPK On

If you want to deploy your application that has to be run on other machines. i REALLY suggest you to use docker. You will build a docker image in local that contain your application and all of the dependencies you need the user just has to install docker, get your docker image and run it on his machine. https://docs.docker.com/get-started/

0
sancelot On

If you want to deploy a python application , you can use cx_freeze to package it. It will provide you a binary ready to execute