CloudLinux.ro
Dev environments

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 pricing

Related tutorials