I'm using Jupyter Notebook, and matplotlib.pyplot is not working. I'm using Python 2.7 in Ubuntu 14.04.

Image of the error message


Your code got the following error message:

ImportError: numpy.core.multiarray failed to import

Change your Python code like this and then test it first in the terminal:

:~$ python
>>> import numpy
>>> from numpy import core
>>> from numpy.core import multiarray as ma  

If you also have python-matplotlib installed, the first line of code to enable plotting in the current Jupyter Notebook is %matplotlib inline

Your Jupyter Notebook also shows another error message:

RuntimeError: module compile against API version 0xa but this version of numpy is 0x9

numpy from Anaconda is not compatible with ipython or some other package that you have installed. This would not happen if you installed the python-numpy, ipython, and python-matplotlib packages from the default Ubuntu repositories. I have installed Jupyter Notebook in Ubuntu 14.04 with the command sudo apt-get -y install ipython ipython-notebook && pip install --user jupyter and used it with ipython, python-matplotlib and python-numpy also from the default Ubuntu repositories without any problems.

To install jupyter-notebook in Ubuntu 18.04-19.10 open the terminal and type:

sudo apt install python-all python3-pip python3-notebook jupyter jupyter-core python-ipykernel

To install jupyter-notebook in Ubuntu 20.04 and later open the terminal and type:

sudo apt install python-all python3-pip jupyter-notebook jupyter