简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM