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.
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.
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.
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.
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
Execute this from file this will work:-
import pip
pip.main(["install","matplotlib"])
this does not work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With