ModuleNotFoundError: No module named 'matplotlib'

Question:

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.

Asked By: Atticus

||

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

Answered By: Eliethesaiyan

Run this from your code:

import pip
pip.main(["install","matplotlib"])
Answered By: Narendra
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.