Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

anaconda cannot import matplotlib.pyplot

Tags:

python

I am getting this error when I am trying to import "matplotlib.pyplot". I cant even install matplotlib.pyplot through conda install.

It shows this:

import matplotlib.pyplot Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'matplotlib.pyplot'

like image 890
rita123 Avatar asked Apr 19 '17 16:04

rita123


2 Answers

As reported here, when you use Anaconda, install the packet using conda. In this case, the right instruction to use (on Ubuntu 18.04) is:

conda install -c conda-forge matplotlib

This will solve the problem.

If you use pip (you can), you will mess up all the dependencies (and for instance, the probability that other scripts/programs do not work anymore is not null: if you use Spyder, you will have big dependencies problem to face).

Optional:

In order to always avoid problem like this, I recommend you to use Virtual Enviroment:

Whats is it?

Geeksforgeeks explains it clearly.

How?

A step-by-step guide is always useful.

like image 102
Leos313 Avatar answered Nov 09 '22 23:11

Leos313


It could be that it's running your default Python installation instead of the one installed with Anaconda. Try prepending this to the top of your script:

#!/usr/bin/env python

If that does not work, try installing matplotlib with pip, then try again:

pip install matplotlib

Let me know if that works for you.

like image 23
Robert Valencia Avatar answered Nov 10 '22 01:11

Robert Valencia