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
matplotlib full tutorial

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.

pip  -- Press Enter

-- If you don't have a pip then

cd path_of_directory_of_get-pip_script

Run the get-pip.py script to install pip by writing the following code in cmd (command prompt) to install pip:

"python .\get-pip.py"

Now in cmd type the following code to install matplotlib with its dependencies:

pip install matplotlib

The error will be resolved, if not then follow through the end of this post.

Read: What is Matplotlib

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:

sudo apt-get install python3-matplotlib

If you want to install it with pip for Python 2.7, you need to use pip:

sudo pip install matplotlib

If the error still arises, follow through to the end of the post.

Read: How to install matplotlib

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:

sudo pip3 install matplotlib

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.

virtualenv environment_name   -- environment_name specifies the name of 
                              -- the environment variable created

Install matplotlib inside of your virtual environment.

pip3 install matplotlib

Now, install ipykernel inside your virtual environment.

pip3 install ipykernel

Connect your jupyter kernel to your new environment.

sudo python3 -m ipykernel install

When you start your Jupyter Notebook, you will see the option to select an environment and select the environment you have created that has matplotlib installed. Now, you are good to go with it.

Read: What is a Python Dictionary 

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:

#!/usr/bin/env python

If that does not work, restart the terminal and try installing matplotlib with conda in conda prompt or cmd, and see if it works.

conda install matplotlib

If the problem is still not resolved, 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 compatible with your Python version installed.
  • If the python installed is 64 bits version with matplotlib is 32 bits. Make sure they are the same.
  • Make sure to add the PATH variable for system and environment variables with the path to the python.
  • If the pip version is outdated, upgrade it to the latest version.
python -m pip install
  • Also, make sure that there are no typos in the import statement.
  • If the error still exists 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