How to set up Python virtual environments
Updated 11/29/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
Error tracking for your applications with GlitchTip
Catch production exceptions with the Sentry SDKs on a small server: the project, the DSN, alerts and uptime.
Updated 11/29/2026Dev environmentsTest your application's email with smtp4dev
Send the email from Laravel, WordPress, Node or Python to a test SMTP server and read it in a web inbox, without it ever reaching real customers.
Updated 11/29/2026Dev environmentsHow to set up a staging environment
Test changes on a copy of production before shipping them, to avoid surprises.
Updated 11/29/2026