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.
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 virtualenv2. Using virtualenv
# Create a new environment named pythonEnv
virtualenv pythonEnv
# Activate the environment
cd pythonEnv
source bin/activate
# Deactivate when done
deactivate3. 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 environmentSwitch between environments: workon pythonEnv Deactivate the current environment: deactivate Remove an environment:
rmvirtualenv pythonEnv4. 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 installSigned-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.
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.
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.
