Fundamentals 4 min read

Master Python Virtual Environments: Install and Use virtualenv & virtualenvwrapper

This guide explains how to install virtualenv, create and manage isolated Python environments, and leverage virtualenvwrapper for easier environment handling, including essential commands, configuration steps, and troubleshooting tips for macOS users.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Python Virtual Environments: Install and Use virtualenv & virtualenvwrapper

virtualenv is a tool for creating isolated Python environments. It builds a folder containing all necessary executables and packages required by a Python project.

After installing Python, pip, and setuptools, you can create a virtualenv, allowing multiple Python versions to coexist on the same machine without interference. Environments can be activated, deactivated, or removed as needed.

1. Install virtualenv

# Install Python (macOS example)
brew install python
# Install pip and setuptools (if not already present)
sudo easy_install pip
# Install virtualenv via pip
pip install virtualenv

2. Using virtualenv

# Create a new environment named pythonEnv
virtualenv pythonEnv
# Activate the environment
cd pythonEnv
source bin/activate
# Deactivate when done
deactivate

3. Manage environments with virtualenvwrapper

Install virtualenvwrapper: pip install virtualenvwrapper Configure environment variables (add to ~/.bash_profile): source /usr/local/bin/virtualenvwrapper.sh Reload the profile: source ~/.bash_profile Create a new environment:

mkvirtualenv pythonEnv          # creates ~/Envs/pythonEnv
mkvirtualenv python3Env -p python3.5  # creates a Python 3.5 environment

Switch between environments: workon pythonEnv Deactivate the current environment: deactivate Remove an environment:

rmvirtualenv pythonEnv

4. Other useful commands and troubleshooting

lsvirtualenv

– list all virtual environments. cdvirtualenv – navigate to the directory of the currently active environment. cdsitepackages – go directly to the site-packages folder. lssitepackages – list contents of site-packages.

If installing pip with easy_install raises ImportError: No module named extern, the macOS‑bundled Python 2.7 lacks the extern module. Download it from https://pypi.python.org/pypi/extern/0.1.0 , extract, and install:

tar zxf extern-0.1.0.tar.gz && python setup.py install
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.

DevelopmentvirtualenvpipEnvironmentvirtualenvwrapper
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.