is there more simple and easy to remember approach when you want to install lets say 10 python modules on Linux Debian (or Ubuntu), where some of these modules need to be exact versions? Lets say “gevent>=23.9.0”
Is this now new universal Linux way to install bigger number of modules where some needs to have certain version number or can you name better way? My main concern is cross-distribution compatibility and easy for the layman to run the .py app (ideally without non standard prefixes where standard prefix is "python " or “python3” or just “./app.py”)?
I’m sure there are multiple solutions where one of them could be simply to script the entire process of prerequisites installation and python app start. Example of such run.sh:
#!/bin/bash
cd "$(dirname "$0")"
# Create python environment
if [ ! -d ".venv" ]; then
echo "Creating virtual environment..."
python3 -m venv .venv
fi
# Activate the virtual environment
echo "Activating virtual environment..."
source .venv/bin/activate
# Install specific dependencies without using requirements.txt
echo "Installing dependencies..."
pip install "gevent>=23.9.0" "flask==2.3.2" "requests>=2.28.0,<3.0.0"
# pip install -r requirements.txt
echo "Running the application..."
python3 app.py
You can either hard code the dependencies into the script or use requirements files. Once the enthronement is setup the app will run. In this case we will start flask server with app.py:
from flask import Flask
# Create the Flask app
app = Flask(__name__)
# Define a simple route
@app.route('/')
def home():
return "testing.."
# Run the app if this file is executed
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
Example of the above code running python app with bash script: