Master Linux Python Virtual Environments with virtualenv & virtualenvwrapper
This guide walks you through setting up and managing Python virtual environments on Linux Ubuntu 18.04 using virtualenv and virtualenvwrapper, covering installation, configuration, common commands, and tips for handling multiple project dependencies, illustrated with step‑by‑step commands and screenshots.
Introduction
Hello everyone, this article shows how to use Python virtual environments on Linux from scratch.
Why a virtual environment?
Virtual environments isolate third‑party packages so different projects can use different versions of Django or other libraries without conflict.
Django 1.5 (old project)
Django 1.8 (recent project)
Django 2.0+ (new project)
Linux environment overview
The examples run on Ubuntu 18.04 with the system Python 3.6.9 and the latest pip.
Update pip with:
sudo python3 -m pip install --upgrade pipInstallation
Install virtualenv and virtualenvwrapper:
pip install virtualenvpip install virtualenvwrapperConfiguration
Create a directory for environments: mkdir $HOME/.virtualenvs or mkdir .virtualenvs Make the directory visible: ls -al Find Python and virtualenvwrapper locations:
which python3 which virtualenvwrapper.shEdit .bashrc to add:
export WORKON_HOME=$HOME/.virtualenvs
source ~/.local/bin/virtualenvwrapper.sh
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3Then reload:
source .bashrcCommon commands
mkvirtualenv spider– create and activate a new environment named spider. deactivate – exit the current environment. workon or lsvirtualenv – list all environments. rmvirtualenv flask – delete the flask environment. workon flask – switch to the flask environment.
Tips: workon can switch environments without deactivating first, and tab‑completion works for virtual‑env commands.
Conclusion
The article demonstrated how to set up and manage Python virtual environments on Linux, providing essential commands and configuration steps for isolated development.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
