Without a virtual environment every package lands in one place, so if one project needs Django 4 and another needs Django 5, one of them breaks. A virtual environment gives each project its own set of packages and keeps the system Python clean.
How it works
Creating an environment makes a folder containing:
bin/python: a link to the interpreter that created it, same version.lib/pythonX.Y/site-packages/: where the project’s packages go.bin/activate: a script that puts the environment’sbinfirst in your shell’sPATH.
Once activated, python and pip point at the environment instead of the system.
Example: the full workflow
python3 -m venv .venv
source .venv/bin/activate
pip install flask requests
pip freeze > requirements.txt
deactivate
On another machine or on the server:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
On Windows the activation command is .venv\Scripts\activate. Add .venv/ to your .gitignore.
Common mistakes and mix-ups
- Installing outside the environment: you forgot to activate, the package went elsewhere, and the app throws
ModuleNotFoundError. Check withwhich python. externally-managed-environment: modern Linux distributions blockpip installinto the system Python; a virtual environment is the fix: see the error page.- Moving an environment between machines: paths are baked into its files, so copying it doesn’t work. Recreate it.
- It isn’t a container: unlike Docker, it doesn’t isolate files or networking, only packages.
On ArabyHost
On AI/Developer plans, Setup Python App creates the environment for you with the version you choose from 3.9 to 3.12, at a path like /home/USER/virtualenv/myapp/3.12/, and shows a ready-to-copy activation command at the top of the app’s page for use over SSH. In cron jobs, call the environment’s interpreter directly:
/home/USER/virtualenv/mybot/3.12/bin/python /home/USER/mybot/bot.py
You can also add environment variables on the same app page. Full steps for a web app are in the Flask deployment guide.
FAQ
What's the difference between venv and virtualenv?
venv is built into Python since 3.3; virtualenv is an older third-party package that does the same job with a few extra features. For most projects venv is all you need.
Should I commit or upload the virtual environment folder?
No. An environment is tied to the path and system it was created on. Ship requirements.txt and recreate the environment on the server.
Do I have to activate it every time?
Activation is just a convenience for your terminal. You can call the environment's interpreter by its full path, which is the right approach in cron jobs.