pythonpython-3.xlinuxpy2exe

Executable Python program with all dependencies for Linux


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


Solution

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