Fundamentals 6 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Python Virtual Environments on Linux with virtualenv & virtualenvwrapper

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 pip

Installation

Install the required packages:

Install virtualenv: pip install virtualenv Install virtualenvwrapper:

pip install virtualenvwrapper

Configuration

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 python3

After editing, reload the configuration:

source .bashrc

Common 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DevelopmentPythonLinuxvirtualenvpipvirtualenvwrapper
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.