Table of Contents
If you are getting an error saying ‘No module named matplotlib’, it means that the matplotlib library is not installed in your Python environment. To fix this, you can install the matplotlib library using the command pip install matplotlib in the terminal/command prompt. Once installed, you should be able to import the matplotlib library in your code and use it.
One common error you may encounter when using Python is:
no module named 'matplotlib'
This error occurs when Python does not detect the library in your current environment.
This tutorial shares the exact steps you can use to troubleshoot this error.
Step 1: pip install matplotlib
Since matplotlib doesn’t come installed automatically with Python, you’ll need to install it yourself. The easiest way to do so is by using pip, which is a package manager for Python.
You can run the following pip command to install matplotlib:
pip install matplotlib
In most cases, this will fix the error.
Step 2: Install pip
If you’re still getting an error, you may need to install pip. Use to do so.
You can also use to upgrade pip to the latest version to ensure that it works.
You can then run the same pip command as earlier to install matplotlib:
pip install matplotlib
At this point, the error should be resolved.
Step 3: Check matplotlib and pip Versions
If you’re still running into errors, you may be using a different version of matplotlib and pip.
which python python --version which pip
If the two versions don’t match, you need to either install an older version of matplotlib or upgrade your Python version.
Step 4: Check matplotlib Version
Once you’ve successfully installed matplotlib, you can use the following command to display the matplotlib version in your environment:
pip show matplotlib Name: matplotlib Version: 3.1.3 Summary: Python plotting package Home-page: https://matplotlib.org Author: John D. Hunter, Michael Droettboom Author-email: [email protected] License: PSF Location: /srv/conda/envs/notebook/lib/python3.7/site-packages Requires: cycler, numpy, kiwisolver, python-dateutil, pyparsing Required-by: seaborn, scikit-image Note: you may need to restart the kernel to use updated packages.
Note: The easiest way to avoid errors with matplotlib and Python versions is to simply install , which is a toolkit that comes pre-installed with Python and matplotlib and is free to use.
The following tutorials explain how to fix other common problems in Python: