Install Matplotlib Using pip, the Standard Python Package Manager

Matplotlib is a Python library for creating charts, graphs, and other visualizations. The fastest way to install it is through pip, which is the package manager that comes with Python. Open your command line or terminal and type a single command — pip will download and install Matplotlib and everything it needs to run.

Before you start, make sure Python is installed on your computer. You can check this by opening your terminal or command prompt and typing python --version or python3 --version. If you see a version number, Python is ready. If you see an error, you need to install Python first from python.org.

Once Python is confirmed, the installation takes one line. On Windows, macOS, or Linux, open your terminal and type exactly this:

pip install matplotlib

Press Enter and wait. Pip will show you progress as it downloads and installs Matplotlib. When it finishes, you will see a message saying "Successfully installed" followed by the version number. That is all — Matplotlib is now ready to use in your Python scripts.

Key Takeaways

  • Matplotlib installs in one command using pip: pip install matplotlib
  • Check that Python is installed first by typing python --version in your terminal.
  • If pip is not found, you may need to use pip3 instead, or reinstall Python with pip included.
  • After installation finishes, test it by opening Python and typing import matplotlib — no error means it worked.
  • Virtual environments keep Matplotlib separate from other projects and prevent version conflicts.

Use pip3 If pip Does Not Work

On some computers, especially macOS and Linux, the command pip may not be recognized. Instead, type pip3 install matplotlib. This happens because your system has both Python 2 and Python 3 installed, and pip3 specifically points to Python 3, which is what you need.

If you get an error saying "pip3: command not found", Python may not have been installed with pip. Go to python.org, download the latest version, and run the installer. Make sure the checkbox that says "Add Python to PATH" (Windows) or the equivalent option is checked during installation. Then try the pip3 command again.

Install Matplotlib Inside a Virtual Environment

A virtual environment is a separate folder on your computer where Python packages live for one project only. This prevents Matplotlib from one project from interfering with Matplotlib in another project if they need different versions. Creating a virtual environment takes two steps and is worth doing if you work on multiple Python projects.

First, open your terminal and navigate to the folder where your project lives. Then create the virtual environment by typing:

python -m venv myenv

Replace "myenv" with any name you want — it is just the name of the folder that will hold your packages. Press Enter. Python will create a new folder with that name.

Next, activate the virtual environment. On Windows, type:

myenv\Scripts\activate

On macOS or Linux, type:

source myenv/bin/activate

Your terminal prompt will change — you will see the environment name in parentheses at the start of the line. Now type pip install matplotlib as usual. Matplotlib will install only inside this virtual environment, not on your whole computer.

Verify the Installation Worked

After pip finishes, test whether Matplotlib is actually installed and working. Open Python by typing python or python3 in your terminal. You will see the Python prompt, which looks like >>>.

Type this line exactly:

import matplotlib

Press Enter. If nothing happens — no error message appears — Matplotlib is installed correctly. If you see an error like "ModuleNotFoundError: No module named 'matplotlib'", the installation did not complete. Go back and run the pip install command again, and check that no errors appeared during the download.

To exit Python, type exit() and press Enter. You are now back at your terminal prompt.

Troubleshoot Common Installation Problems

If pip says "command not found" or "is not recognized", Python was not added to your system PATH during installation. Reinstall Python from python.org and make sure to check the box that says "Add Python to PATH" before clicking Install.

If the download starts but then stops with an error about permissions, you may be trying to install to a system folder you do not have permission to change. Use a virtual environment instead, or on macOS and Linux, try typing pip install --user matplotlib to install just for your user account.

If the import test shows "ModuleNotFoundError" but pip said the installation succeeded, you may have multiple Python versions on your computer and pip installed to the wrong one. Try pip3 install matplotlib instead, or create a virtual environment to be certain which Python version you are using.

Update Matplotlib If You Already Have It Installed

If Matplotlib is already on your computer but you want the newest version, pip can update it. Type:

pip install --upgrade matplotlib

Pip will check the version you have, compare it to the latest available, and download the new one if an update exists. This is useful if you are following a tutorial that uses features from a newer version than what you have.

To see which version you currently have, type pip show matplotlib. Pip will display the version number, where it is installed, and what other packages depend on it.

Frequently Asked Questions

Do I need to install anything else before Matplotlib?

No. Pip will automatically download and install NumPy and other libraries that Matplotlib needs to run. You only type one command.

Can I use Matplotlib without pip?

Yes, but it is slower. You can download the source code from matplotlib.org and install it manually, but pip is the standard way and handles all the dependencies for you.

What if I am using Anaconda instead of regular Python?

Anaconda has its own package manager called conda. Instead of pip, type conda install matplotlib. Anaconda often comes with Matplotlib already installed, so check first by typing import matplotlib in Python.

Will Matplotlib work on my Mac if I have an M1 or M2 chip?

Yes. Matplotlib supports Apple Silicon chips. If you installed Python from python.org, pip will download the correct version automatically. If you have problems, Anaconda often handles M1 and M2 Macs more smoothly.

How do I uninstall Matplotlib if I do not need it anymore?

Type pip uninstall matplotlib and press Enter. Pip will ask you to confirm, then remove it. This does not affect other packages or Python itself.