modulenotfounderror: no module named ‘matplotlib’
In this Python tutorial, we will discuss the modulenotfounderror: no module named ‘matplotlib’ and we shall also cover the following topics:
- modulenotfounderror: no module named matplotlib windows 10
- modulenotfounderror: no module named ‘matplotlib’ ubuntu
- modulenotfounderror no module named ‘matplotlib’ python 3
- modulenotfounderror no module named ‘matplotlib’ jupyter notebook
- modulenotfounderror no module named ‘matplotlib’ anaconda
- modulenotfounderror: no module named ‘matplotlib’ pycharm
- modulenotfounderror: no module named ‘matplotlib.pyplot’; ‘matplotlib’ is not a package
Table of Contents
modulenotfounderror: no module named matplotlib windows 10
Check if you have pip installed already, simply by writing pip in the python console. If you don’t have pip, get a python script called get-pip.py from the internet and save it to your local system. pip is the python package installer.
Take note of where the file got saved and change the current directory to that directory from the command prompt.
Run the get-pip.py script to install pip by writing the following code in cmd (command prompt) to install pip:
Now in cmd type the following code to install matplotlib with its dependencies:
The error will be resolved, if not then follow through the end of this post.
modulenotfounderror: no module named ‘matplotlib’ ubuntu
If you don’t have matplotlib installed then to install Matplotlib for Python 3 through the APT package manager, you need the package python3-matplotlib:
If you want to install it with pip for python 2.7, you need to use pip:
If the error still arises, follow through to the end of the post.
modulenotfounderror no module named ‘matplotlib’ python 3
You can install matplotlib with pip for python 3 and above, you just need to use pip3.
Open the python console and execute the command given below:
By executing the above code, the matplotlib for your python will be installed.
modulenotfounderror no module named ‘matplotlib’ jupyter notebook
Create a virtual environment inside your project directory. If you don’t have it, you have to install virtualenv by executing the following command in the cmd/terminal.
Install matplotlib inside of your virtual environment.
Now, install ipykernel inside your virtual environment.
Connect your jupyter kernel to your new environment.
When you start your jupyter notebook, you will see the option to select an environment, select the environment you have created which has matplotlib installed. Now, you are good to go with it.
modulenotfounderror no module named ‘matplotlib’ anaconda
If you have Python installed previously, before installing Anaconda, the reason could be that it’s running your default Python installation instead of the one installed with Anaconda. You have to try prepending this to the top of your script:
If that does not work, restart the terminal and try installing matplotlib with conda in conda prompt or cmd, and see if it works.
If the problem still not resolves, maybe you have to create a virtual environment as given in the above topics.
modulenotfounderror: no module named ‘matplotlib’ pycharm
You can get this error if you are using pycharm and have matplotlib.py in your current working directory. You have to just delete or rename the matplotlib.py file to resolve the issue, most probably it will work.
modulenotfounderror: no module named ‘matplotlib.pyplot’; ‘matplotlib’ is not a package
The error is caused because of the following reasons, check them out:
- Make sure that the version of matplotlib you are installing is compaitible with your python version installed.
- If the python installed is 64 bits version with matplotlib is 32bits. Make sure they are the same.
- Make sure to add PATH variable for system and environment variables with path to the python.
- If pip version is outdated, upgrade it to the latest version.
- Also make sure that there is no typos in the import statement.
- If the error still exist then, try to check if there is any file matplotlib.py in your working directory. Remove that file, restart the kernel and import matplotib again. That should work.
You may also like reading the following articles.
In this Python tutorial, we have discussed the modulenotfounderror: no module named ‘matplotlib’ and we have also covered the following topics:
- modulenotfounderror: no module named matplotlib windows 10
- modulenotfounderror: no module named ‘matplotlib’ ubuntu
- modulenotfounderror no module named ‘matplotlib’ python 3
- modulenotfounderror no module named ‘matplotlib’ jupyter notebook
- modulenotfounderror no module named ‘matplotlib’ anaconda
- modulenotfounderror: no module named ‘matplotlib’ pycharm
- modulenotfounderror: no module named ‘matplotlib.pyplot’; ‘matplotlib’ is not a package
Python is one of the most popular languages in the United States of America. I have been working with Python for a long time and I have expertise in working with various libraries on Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… I have experience in working with various clients in countries like United States, Canada, United Kingdom, Australia, New Zealand, etc. Check out my profile.
jupyter ModuleNotFoundError: No module named matplotlib
I am currently trying to work basic python — jupyter projects.
I am stuck on following error during matplotlib:
screenshot on jupyter-error 
ModuleNotFoundError: No module named ‘matplotlib‘
I tried to update, reinstall matplotlib aswell in conda and in pip but it still not working.
happy over every constructive feedback
9 Answers 9
In a Notebook’s cell type and execute the code:
and reload the kernel
open terminal and change the directory to Scripts folder where python installed. Then type the following command and hit enter
Hope this will solve the issue.
![]()
I was facing the exact issue. It turns out that it was using the system Python version despite me having activated my virtual environment.
This is what eventually worked.
If you are using a virtual environment which has a name say myvenv , first activate it using command:
Then install module ipykernel using the command:
Finally run (change myvenv in code below to the name of your environment):
Now restart the notebook and it should pick up the Python version on your virtual environment.
[Solved] ImportError: No module named matplotlib.pyplot
The ImportError: No module named matplotlib.pyplot occurs if you have not installed the Matplotlib library in Python and trying to run the script which has matplotlib related code. Another issue might be that you are not importing the matplotlib.pyplot properly in your Python code.
In this tutorial, let’s look at installing the matplotlib module correctly in different operating systems and solve No module named matplotlib.pyplot.
ImportError: No module named matplotlib.pyplot
Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python.
Matplotlib is not a built-in module (it doesn’t come with the default python installation) in Python, you need to install it explicitly using the pip installer and then use it.
If you looking at how to install pip or if you are getting an error installing pip checkout pip: command not found to resolve the issue.
Matplotlib releases are available as wheel packages for macOS, Windows and Linux on PyPI. Install it using pip :
Install Matplotlib in OSX/Linux
The recommended way to install the matplotlib module is using pip or pip3 for Python3 if you have installed pip already.
Using Python 2
Using Python 3
Alternatively, if you have easy_install in your system, you can install matplotlib using the below command.
Using easy install
For CentOs
For Ubuntu
To install matplotlib module on Debian/Ubuntu :
Install Matplotlib in Windows
In the case of windows, you can use pip or pip3 based on the Python version, you have to install the matplotlib module.
If you have not added the pip to the environment variable path, you can run the below command in Python 3, which will install the matplotlib module.
Install Matplotlib in Anaconda
Matplotlib is available both via the anaconda main channel and it can be installed using the following command.
You can also install it via the conda-forge community channel by running the below command.
In case you have installed it properly but it still throws an error, then you need to check the import statement in your code.
In order to plot the charts properly, you need to import the matplotlib as shown below.

report this ad
ModuleNotFoundError: No module named matplotlib
The error “ModuleNotFoundError: No module named matplotlib» is a common error experienced by data scientists when developing in Python. The error is likely an environment issue whereby the matplotlib package has not been installed correctly on your machine, thankfully there are a few simple steps to go through to troubleshoot the problem and find a solution.
ModuleNotFoundError: No module named matplotlib
Your error, whether in a Jupyter Notebook or in the terminal, probably looks like one of the following:
No module named ‘matplotlib’
ModuleNotFoundError: No module named ‘matplotlib’
- Upgrade pip version
- Upgrade or install matplotlib package
- Check if you are activating the environment before running
- Create a fresh environment
- Upgrade or install Jupyer Notebook package
Are you installing packages using Conda or Pip package manager?
It is common for developers to use either Pip or Conda for their Python package management. It’s important to know what you are using before we continue with the fix.
If you have not explicitly installed and activated Conda, then you are almost definitely going to be using Pip. One sanity check is to run conda info in your terminal, which if it returns anything likely means you are using Conda.
Upgrade or install pip for Python
First things first, let’s check to see if we have the up to date version of pip installed. We can do this by running:
Upgrade or install matplotlib package via Conda or Pip
The most common reason for this error is that the matplotlib package is not installed in your environment or an outdated version is installed. So let’s update the package or install it if it’s missing.
Activate Conda or venv Python environment
It is highly recommended that you use isolated environments when developing in Python. Because of this, one common mistake developers make is that they don’t activate the correct environment before they run the Python script or Jupyter Notebook. So, let’s make sure you have your correct environment running.
For virtual environments:
Create a new Conda or venv Python environment with matplotlib installed
During the development process, a developer will likely install and update many different packages in their Python environment, which can over time cause conflicts and errors.
Therefore, one way to solve the module error for matplotlib is to simply create a new environment with only the packages that you require, removing all of the bloatware that has built up over time. This will provide you with a fresh start and should get rid of problems that installing other packages may have caused.
For virtual environments:
Upgrade Jupyter Notebook package in Conda or Pip
If you are working within a Jupyter Notebook and none of the above has worked for you, then it could be that your installation of Jupyter Notebooks is faulty in some way, so a reinstallation may be in order.
Best practices for managing Python packages and environments
- Always use separate environments for your projects and avoid installing packages to your root environment
- Only install the packages you need for your project
- Pin your package versions in your project’s requirements file
- Make sure your package manager is kept up to date
References
Stephen Allwright Twitter
I’m a Data Scientist currently working for Oda, an online grocery retailer, in Oslo, Norway. These posts are my way of sharing some of the tips and tricks I’ve picked up along the way.