Skip to content

Instantly share code, notes, and snippets.

@basaks
Last active June 22, 2017 01:19
Show Gist options
  • Save basaks/b33ea9106c7d1d72ac3a79fdcea430eb to your computer and use it in GitHub Desktop.
Save basaks/b33ea9106c7d1d72ac3a79fdcea430eb to your computer and use it in GitHub Desktop.
virtualenv and virtualenvwrapper

Virtualenv

It is strongly recommended that you install python packages in a virtualenv. Here are some brief steps to install virtualenv on linux:

Install pip

$ sudo apt-get install python-pip

Install virtualenv

$ sudo pip install virtualenv

I store my virtualenvs in a dir ~/venvs

$ mkdir ~/venvs

At this point you are all set to use virtualenv with the standard commands. However, I prefer to use the extra commands included in virtualenvwrapper. Lets set that up.

Install virtualenvwrapper

$ sudo pip install virtualenvwrapper

Set WORKON_HOME to your virtualenv dir

$ export WORKON_HOME=~/venvs

Add virtualenvwrapper.sh to .bashrc.

Add this line to the end of ~/.bashrc so that the virtualenvwrapper commands are loaded.

$ source /usr/local/bin/virtualenvwrapper.sh

Exit and re-open your shell, or reload .bashrc with the command source ~/.bashrc and you’re ready to go.

Create a new virtualenv

$ mkvirtualenv myenv

To create a python3 virtualenv use the following:

$ mkvirtualenv -p python3 myenv

This will create a python3 virtualenv using your system installed python3 version. If you want to install another python3 interpreter, follow this approach.

To exit your new virtualenv, use deactivate:

$ deactivate

To load or switch between virtualenv, use the workon command:

$ workon myenv
@basaks
Copy link
Author

basaks commented Mar 9, 2017

If matplotlib does not play well in a virtualenv, use this:
sudo apt-get -y build-dep matplotlib

Then install matplotlib again in your virtualenv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment