Installing virtualenv and virtualenvwrapper for Python3
virtualenv is a tool to create isolated Python environments.
→ This makes the assumption that your version of Python3 doesn’t come with pip3 bundled by default and you are working on a unix based environment.
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
append the following lines to your .bashrc file :
export VIRTUALENVWRAPPER_PYTHON=`which python3`
export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv`
source `which virtualenvwrapper.sh`
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
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 :
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.