Fundamentals 6 min read

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.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Master Linux Python Virtual Environments with virtualenv & virtualenvwrapper

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 pip

Installation

Install virtualenv and virtualenvwrapper:

pip install virtualenv
pip install virtualenvwrapper

Configuration

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

Edit .bashrc to add:

export WORKON_HOME=$HOME/.virtualenvs
source ~/.local/bin/virtualenvwrapper.sh
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3

Then reload:

source .bashrc

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

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.

DevelopmentPythonLinuxvirtual environmentvirtualenv
Python Crawling & Data Mining
Written by

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!

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.