Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'matplotlib' [duplicate]

I'm trying to run a python program that requires matplotlib, which I've already installed via pip. I am running Python 3.6 locally on my Mac, with my .bash_profile updated to reflect this. The import line in question is as seen below:

import matplotlib.pyplot as plt

Below is the error message I see, as you can figure out from the subject line:

ModuleNotFoundError: No module named 'matplotlib'

And here's what I see if I try pip install matplotlib:

Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/site-packages
Requirement already satisfied: python-dateutil in /usr/local/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: numpy>=1.7.1 in /usr/local/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: pyparsing!=2.0.0,!=2.0.4,!=2.1.2,!=2.1.6,>=1.5.6 in /usr/local/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: pytz in /usr/local/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: six>=1.10 in /usr/local/lib/python3.6/site-packages (from matplotlib)

I've referenced a few other posts like this and this, but without much luck. Am I overlooking an answer that I just didn't follow through with, or could it be something else? Your time is appreciated.

like image 591
Atticus Avatar asked Mar 09 '18 05:03

Atticus


People also ask

Why does matplotlib say no module?

Conclusion # The Python "ModuleNotFoundError: No module named 'matplotlib'" occurs when we forget to install the matplotlib module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install matplotlib command.

How do I know if matplotlib is installed?

To verify that Matplotlib is installed, try to invoke Matplotlib's version at the Python REPL. Use the commands below that include calling the . __version__ an attribute common to most Python packages.

How do I run matplotlib in Jupyter?

Install Matplotlib Make sure you first have Jupyter notebook installed, then we can add Matplotlib to our virtual environment. To do so, navigate to the command prompt and type pip install matplotlib. Now launch your Jupyter notebook by simply typing jupyter notebook at the command prompt.


2 Answers

use pip3 install matplotlib to install matlplot lib. By default, pip will install those package for 2.7 as it the native one. using pip3 makes it specific for python 3, and make sure you have only one version of python 3

like image 146
Eliethesaiyan Avatar answered Oct 06 '22 17:10

Eliethesaiyan


Execute this from file this will work:-

import pip
pip.main(["install","matplotlib"])

this does not work

like image 20
Narendra Avatar answered Oct 06 '22 18:10

Narendra