1

When I type

import matplotlib.pyplot as plt

in my IPython notebook I get

ImportError: No module named matplotlib.pyplot

Shouldn't be this module installed by default? Do I need to extra install it. If it is the case, how can I do it. I use virtual environment on Linux to install stuff (including IPython).

3 Answers 3

3

Matplotlib is not installed by default, there are instructions on the IPython install page to install on linux:

Optionally install additional tools for scientific computing: On Ubuntu or other Debian-based distributions, type at the shell:

sudo apt-get install python-matplotlib python-scipy python-pandas python-sympy python-nose

On Fedora 18 and newer related distributions, use:

sudo yum install python-matplotlib scipy python-pandas sympy
python-nose

Though if you are using a python virtualenv, you should be able to use pip install matplotlib when you are in the virual environment.

Sign up to request clarification or add additional context in comments.

2 Comments

I use Ubuntu and I do not have root privileges. So, I use virtual environment to install locally. I tried pip intall matplotlib in my virtual environment and it worked.
Good point, sudo not needed in the virtual environment, have updated
2

In my Python setup (2.7.3, Linux), I installed matplotlib as well as IPython via pip. matplotlib is available from the normal Python interpreter as well as from IPython (as expected). The order of installation does not matter.

And no, IPython should not have matplotlib installed by default, this does not make sense.

3 Comments

matplotlib is often available as a system package. for instance on Ubuntu, it's python-matplotlib
Right, but when working within a virtualenv or when dealing with a custom Python installation anyway, pip is a great way to install matplotlib. Also, especially regarding matplotlib it can be important to have access to a cutting-edge version. Don't want to miss features such as tight_layout() anymore.
point taken, but you chose a bad example - tight_layout() was introduced in v1.1, which was released in 2011, so any reasonable OS should already offer that. personally, on current Ubuntu I'm on 1.2.1
1

In case you are trying on Python 3, you can install it using:

python3-matplotlib

Hope it helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.