DevOps Buzz
Search…
Bash / Shell
Bitbucket
Distros
Elasticsearch
General
Guidelines / Standards
microk8s
Prometheus
RabbitMQ
VirtualBox
Virtualenv
Setup a virtualenv using virtualenvwrapper

Install virtualenvwrapper and create your first virtualenv

Install virtualenvwrapper
1
sudo pip3 install virtualenvwrapper
Copied!
Edit your bashrc file and add te following content.
~/.bashrc
1
export WORKON_HOME="$HOME/virtualenvs"
2
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
3
source /usr/local/bin/virtualenvwrapper.sh
Copied!
Then run.
1
source ~/.bashrc
Copied!
Create a virtualenv.
1
mkvirtualenv env1
Copied!

Setup .bashrc config

Add the following lines in your ~/.bashrc file.
~/.bashrc
1
# Virtualenvs
2
export WORKON_HOME=~/virtualenvs
3
source /usr/local/bin/virtualenvwrapper.sh
Copied!

Useful commands

Change virtualenv

1
workon yourvirtualenvname
Copied!

"Logout" from a virtualenv

1
deactivate
Copied!

"cd" to your virtualenv automatically

Run this only one time.
1
workon yourvirtualenvname
2
echo 'cd $VIRTUAL_ENV' >> $WORKON_HOME/postactivate
Copied!

References