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
If
matplotlib
does not play well in avirtualenv
, use this:sudo apt-get -y build-dep matplotlib
Then install
matplotlib
again in yourvirtualenv
.