25
Jul 2015
How to install matplotlib using virtualenv on Ubuntu
Tags |
On Computer Technology
This was done on a system with the following specifications:
You’ll probably do fine following the instructions below if you’re using a system with similar specifications.
We’ll be installing matplotlib 1.4.3 .
We assume that there is the following folder hierarchy somewhere on your system:
your_repo
|--- requirements.txt
|--- venv
where:
your_repo
is a folder that you have some Python code using matplotlibvenv
is a folder created using virtualenv venv
; you’ll activate the virtualenv in the your_repo
folder using the . venv/bin/activate
commandrequirements.txt
contains a line to install matplotlib
. For me, this line is matplotlib==1.4.3
sudo apt-get -y build-dep matplotlib
cd your_repo
. venv/bin/activate
pip install -r requirements.txt
The magic is in the sudo apt-get -y build-dep matplotlib
line, which will install all the build dependencies for matplotlib.
Save the following code into check_matplotlib.py
in the your_repo
folder:
import matplotlib.pyplot as pyplot
pyplot.pie([1, 2, 3])
pyplot.show()
Activate the virtualenv if you have not, and run python check_matplotlib.py
. You should see something like this:
And voila, there you have it =)
Based on this answer on Stack Overflow by HiddenGhost.
Was reading Section 2.5 of Think Stats, wanted to install matplotlib on a virtualenv but nothing showed up when I ran the example code in the book. Googled around, tried several answers on Stack Overflow which didn’t work or suggested doing a system-wide installation, but didn’t want to. I have no idea why I tried part of Hidden Ghost’s answer eventually, but then things worked out, so yea =)
And I noticed that I’ve posted 5 entries (including this one) since June, with 3 entries (including this one) in July. Might I be posting too much? Haha… there’s like 1 or 2 more entries in the pipeline.
Disclaimer: Opinions expressed on this blog are solely my own and do not express the views or opinions of my employer(s), past or present.