1

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

Dorian Turba
  • 3,260
  • 3
  • 23
  • 67
OperationJynx
  • 111
  • 2
  • 2
  • 7

3 Answers3

10

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.
Dorian Turba
  • 3,260
  • 3
  • 23
  • 67
  • Hello, thanks for your answer. But how can a .exe run on a mac/linux machine? And also converting it to a .exe is ok, but i wan't to keep the .py file because it runs with parameter, i just want to make it user friendly, so nobody has to download all the packages with pip im using in my project. //Edit: how can i pack everything to a single .exe? – OperationJynx Jan 16 '19 at 08:43
  • 1
    For mac, it create .app, and for linux, executable file. – Dorian Turba Jan 16 '19 at 08:50
  • You have edit your comment and ask : 'how can i pack everything to a single .exe?' so I have edit my answer for you. – Dorian Turba Jan 16 '19 at 08:52
  • Can i still parse parameters when the program is run per console? And when i use --onefile as parameter, i only get a .exe and no .app or something else.. strange – OperationJynx Jan 16 '19 at 08:52
  • Yes, because you ask '-onefile'. Using console, you ask your Python interpreter to run your program. By doing this, you have to install package and everything using pip. What you can do ? for me, default parameter in order to avoid sending parameter or a config file where user can set whatever he want. – Dorian Turba Jan 16 '19 at 08:58
  • You can also directly ask the user with input() and get arg with split() if you want everything in one input : https://stackoverflow.com/questions/19063114/split-an-input-into-two-python-3 – Dorian Turba Jan 16 '19 at 09:17
0

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/

SimbaPK
  • 566
  • 1
  • 7
  • 26
  • 2
    While Docker is great for solving certain portability issues, it doesn't let you create stand-alone executables, and introduces many restrictions on what the application can do (which is by design as Docker containers are sandboxed by default). – Xano May 20 '21 at 15:06
0

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

sancelot
  • 1,905
  • 12
  • 31