Installing virtualenv and virtualenvwrapper for Python3

virtual setup

virtualenv is a tool to create isolated Python environments.

Step 1 : install pip for Python3

python3 -m pip install — upgrade pip

Now, to create a virtual environment for the project that you want to work on.

Step 2 : install virtualenv

pip3 install virtualenv

Step 3 : install virtualenvwrapper

pip3 install virtualenvwrapper

→ virtualenvwrapper is a set of extensions to Ian Bicking’s virtualenv tool. The extensions include wrappers for creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies.

Step 4 : virtualenvwrapper need environment variable

vim ~/.bashrc

append the following lines to your .bashrc file :

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=`which python3`
export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv`
source `which`

In this environment variables, If you want virtualenvwrapper to work with different python version, then just update

export VIRTUALENVWRAPPER_PYTHON=`which python[version_number]`

or you can give the path also.

Step 5 : reload your profile

source ~/.bashrc

Installation setup Done.

→ Basic commands :

1. Created virtual environment :

virtualenv -p $(which python3) name_myenv

here, [ -p ] option is to select the python interpreter version.

[ name_myenv ] is the name which you would like to give to the virtual environment.

Alternative to create virtual environment :

mkvirtualenv --python=python3 name_myenv2

This command will create the virtual environment with python 3 interpreter and make it activate at the same time.

2. Enter in virtual environment :

source name_myenv/bin/activate

3. Exit form virtual environment :


4. To delete environment :

rm -rf name_myenv

5. List all virtual environment :


NOTE : lsvirtualenv is a part of virtualenvwrapper.

connect me on :

Developer | ARTH Learner @LinuxWorld | IIEC RISE Student | ML • DL • DevOps [MLOps] Enthusiast | AWS • GCP • Azure ☁️