Executable Python program with all dependencies for Linux

Question:

Is there a way to deploy a Python program that includes all dependencies on a Linux system?

I have used py2exe to "compile" a python script with all modules to a standalone .exe, but that’s obviously only working on Windows.
Is there an easy way to e.g. develop a flask server with Python and have all its scripts and modules bundled together so that it can be executed on Linux without having to install the dependencies with pip? (assuming python3 is installed on the Linux platform, but no specific Python modules).

Asked By: user2557097

||

Answers:

You can install the dependencies in the same directory as the program as mentioned here and then package it any way you want. This way the program can always access the dependencies even if they are not installed in the system the program is being executed in.

Answered By: BBloggsbott

Use PyInstaller in Linux based systems
PyInstaller is a program used to convert Python scripts into standalone deployable applications.

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.

Answered By: Melan Rashitha
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.