How to set up Python virtual environments
Updated 7/20/2026
Python virtual environments isolate each project's packages, so different versions do not clash and you do not affect the system.
1. Install Python and venv
apt-get update -y
apt-get install -y python3 python3-venv python3-pip
2. Create a virtual environment
cd /var/www/project
python3 -m venv venv
3. Activate it
source venv/bin/activate
Now pip install installs packages only in this environment, not system-wide.
4. Install dependencies
pip install -r requirements.txt
5. Leave the environment
deactivate
Multiple Python versions
If you need different Python versions (not just packages), use pyenv, the Python equivalent of nvm.
In production
Run the Python app (for example with Gunicorn) as a persistent service, see how to create a systemd service, behind a reverse proxy.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
How to create a systemd service for your app
Make your app start automatically and restart itself if it stops, with a systemd service.
Updated 7/20/2026Dev environmentsHow to keep sessions running after disconnect with tmux
tmux keeps your terminal sessions alive even after you close SSH, ideal for long-running tasks.
Updated 7/20/2026Dev environmentsHow to install PHP (multiple versions) and Composer
Install the PHP version your project needs, along with Composer for package management.
Updated 7/20/2026