Setting Up Python Virtual Environments with virtualenv and virtualenvwrapper

Environment Setup

  • Operating System: Windows 10
  • Python Version: 3.6.7

virtualenv

Installation

virtualenv creates isolated Python environments, allowing different project dependencies to remain separate. Install it using pip on Windows:

pip install virtualenv

Creating a Virtual Environment

Use the virtualenv command with appropriate parameters to create a new environment:

virtualenv --no-site-packages -p C:\Python36\python.exe myenv

Parameters explained:

  • --no-site-packages: Prevents access to global site-packages
  • -p: Specifies the Python interpreter to use
  • myenv: Directory name for the new environment

Activating and Deactivating

Navigate to the Scripts directory within your virtual environment and run the activate script:

F:\myenv>cd Scripts

F:\myenv\Scripts>activate

(myenv) F:\myenv\Scripts>

Note: Use Command Prompt (cmd.exe) instead of PowerShell. The activate script does not properly update the prompt indicator in PowerShell.

To deactivate the virtual environment:

(myenv) F:\myenv\Scripts>deactivate
F:\myenv\Scripts>

Command Options

Basic Usage

virtualenv [OPTIONS] DEST_DIR

Available Options

Option Description
--version Display installed version
-h, --help Show help message
-v, --verbose Increase output verbosity
-q, --quiet Reduce output verbosity
-p PYTHON_EXE, --python=PYTHON_EXE Specify Python interpreter path
--clear Clear non-root enstallations and rebuild
--no-site-packages Block access to global site-packages
--system-site-packages Allow access to global site-packages
--unzip-setuptools Extract Setuptools or Distribute during install
--relocatable Make existing environment relocatable
--distribute Use Distribute instead of Setuptools
--extra-search-dir=SEARCH_DIRS Search directories for packages
--never-download Prevent downloading from network
--prompt=PROMPT Set custom prompt prefix

virtualenvwrapper

virtualenvwrapper provides convenience wrappers around virtualenv, simplifying workflow. Ensure virtualenv is installed first.

Linux Installation

pip install virtualenvwrapper

Add the following to ~/.bashrc:

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

Apply changes:

source ~/.bashrc

Windows Installation

pip install virtualenvwrapper-win

After installation, configure the environment variable:

  1. Open System Properties
  2. Navigate to Advanced System Settings
  3. Click Environment Variables
  4. Under System Variables, create a new variable:
    • Variable name: WORKON_HOME
    • Variable value: Absolute path for storing virtual environments

Common commands with virtualenvwrapper on Windows:

workon          # List available environments
workon myenv    # Activate specific environment
deactivate      # Deactivate current environment
rmvenv myenv    # Remove an environment

Tags: python virtualenv virtualenvwrapper development-tools environment-management

Posted on Wed, 27 May 2026 21:25:09 +0000 by gutogouveia