Run these commands in the terminal. The $
means your terminal prompt.
$ sudo apt-get update
$ sudo apt-get install python-pip
$ sudo pip install virtualenv
$ sudo pip install virtualenvwrapper
Open up your .bashrc
file. Example: gedit ~/.bashrc
. If you use zsh, then edit ~/.zshrc
instead. Put these lines at the bottom:
alias mkve3='mkvirtualenv --python=`which python3`'
export WORKON_HOME=~/Envs
source /usr/local/bin/virtualenvwrapper.sh
Save the file and type: source ~/.bashrc
. Now it's installed and ready.
- Create a Python 2 virtualenv:
mkvirtualenv my_venv
- Create a Python 3 virtualenv:
mkve3 my_other_venv
- Deactivate a virtualenv:
deactivate
- Work on an existing virtualenv:
workon my_virtualenv_name
(tab-completion should work)
Once a virtualenv is activated, you can install packages with pip: pip install requests
.
You don't need to use sudo
.
Your Python packages will be located at ~/Envs
.