Master Python Virtual Environments on Linux with virtualenv & virtualenvwrapper
This guide walks you through setting up Python 3.6.9 on Ubuntu 18.04, installing virtualenv and virtualenvwrapper, configuring the shell, and using common commands to create, activate, list, and delete isolated Python environments, complete with step‑by‑step code snippets and screenshots.
Introduction
The article explains why Python virtual environments are essential for avoiding package version conflicts when working on multiple projects, especially with different Django versions, and introduces virtualenv and virtualenvwrapper as the standard tools.
Linux Environment Overview
The tutorial runs on Ubuntu 18.04, which ships with Python 3.6.9 and an up‑to‑date pip. The command to upgrade pip is:
sudo python3 -m pip install --upgrade pipInstallation
Install the required packages:
Install virtualenv: pip install virtualenv Install virtualenvwrapper:
pip install virtualenvwrapperConfiguration
Create a directory to store virtual environments (e.g., $HOME/.virtualenvs or .virtualenvs in the home folder) and add the following lines to .bashrc (requires basic vim knowledge):
export WORKON_HOME=$HOME/.virtualenvs</code>
<code>source ~/.local/bin/virtualenvwrapper.sh # path obtained via which virtualenvwrapper.sh</code>
<code>VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 # path obtained via which python3After editing, reload the configuration:
source .bashrcCommon Commands
mkvirtualenv spider– create and activate a new environment named spider . deactivate – exit the current virtual environment. workon or lsvirtualenv – list all available environments. rmvirtualenv flask – delete the flask environment. workon flask – switch to the flask environment.
Command Summary
lsvirtualenv / workon: list all virtual environments. mkvirtualenv spider: create and activate a new environment called spider . deactivate: exit the current environment. rmvirtualenv spider: delete the spider environment. workon flask: activate the flask environment.
Conclusion
The guide provides a concise, practical workflow for managing isolated Python environments on Linux, covering installation, configuration, and everyday commands, enabling developers to avoid dependency clashes across projects.
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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
