Installing Matplotlib takes just one command in most cases. But if you’re hitting errors like ModuleNotFoundError, pip not recognized, or a blank plot that refuses to show up — you’re in the right place.
In this guide, I’ll walk you through every way to install Matplotlib: using pip, conda, a virtual environment, and your Linux package manager. I’ll cover Windows, macOS, and Linux, and I’ll also show you how to verify the install, run your first plot, fix common errors, and upgrade or uninstall it when needed.
What Is Matplotlib and Why Use It?
Matplotlib is a Python library for creating charts and visualizations — line graphs, bar charts, scatter plots, histograms, you name it. It’s one of the most-used libraries in data science, machine learning, and everyday data analysis.
If you’ve seen a Python-generated chart anywhere online, there’s a good chance it was built with Matplotlib.
It works well with NumPy, Pandas, and Jupyter Notebooks, making it a staple in the Python data stack.
Before You Install — Quick Checklist
Before running the install command, check these three things:
- Python is installed. Open your terminal and run python –version or python3 –version. You should see Python 3.8 or higher. If not, download it from python.org.
- pip is available. Run pip –version. If pip isn’t recognized, run python -m ensurepip –upgrade to install it.
- You’re in the right environment. If you’re using a virtual environment or Anaconda, make sure it’s activated first.
Install Matplotlib Using pip (Recommended)
For most users on any operating system, this is the command you want:
python -m pip install matplotlib
You can refer to the screenshot below to see the output.

I always recommend using python -m pip instead of just pip; it makes sure you’re installing into the exact Python environment you’re working in, not some other Python version silently installed on your machine.
To also upgrade pip before installing (good practice):
python -m pip install -U pip
python -m pip install -U matplotlib
You can refer to the screenshot below to see the output.

Install Matplotlib on Windows — Step by Step
Here’s the exact process on Windows 10 or 11:
Step 1: Open Command Prompt (search for cmd in the Start menu).
Step 2: Check your Python version:
python --version
Step 3: Upgrade pip:
python.exe -m pip install --upgrade pip
Step 4: Install Matplotlib:
python -m pip install matplotlib
Step 5: Verify it worked:
python -c "import matplotlib; print(matplotlib.__version__)"
You should see something like 3.10.1 printed in the terminal. If you do — you’re good to go.
Tip: If you get python is not recognized as an internal or external command, Python wasn’t added to PATH during installation. Reinstall Python and tick the “Add Python to PATH” checkbox on the first installer screen.
Install Matplotlib on macOS
macOS ships with its own system Python, but you don’t want to use that for your projects. I’d strongly recommend using a separate Python from python.org or Homebrew.
If you installed Python from python.org or Homebrew:
python3 -m pip install matplotlib
Verify the install:
python3 -c 'import matplotlib; print(matplotlib.__version__, matplotlib.__file__)'
This prints both the version and the file path, so you can confirm you’re using the right Python installation.
macOS tip: If you run which python3 and see /usr/bin/python3, that’s the system Python. That’s usually fine for installing packages, but for serious projects, use a virtual environment (covered below).
Install Matplotlib on Ubuntu/Linux
On Linux, you have two good options: pip or your system’s package manager.
Using pip (gets the latest version):
python3 -m pip install matplotlib
Using the system package manager (simpler, but may install an older version):
- Debian / Ubuntu:
sudo apt-get install python3-matplotlib
- Fedora:
sudo dnf install python3-matplotlib
- Red Hat:
sudo yum install python3-matplotlib
- Arch Linux:
sudo pacman -S python-matplotlib
I personally prefer pip for Linux when working on data projects, since the apt/dnf version can lag a few releases behind the latest Matplotlib.
Install Matplotlib with Conda/Anaconda
If you’re working in Anaconda or Miniconda, use conda to install Matplotlib so all dependencies are managed together properly.
From the Anaconda default channel:
conda install matplotlib
From the community-maintained conda-forge channel (recommended — usually more up to date):
conda install -c conda-forge matplotlib
After installation, verify it:
python -c "import matplotlib; print(matplotlib.__version__)"
Install Matplotlib in a Virtual Environment (Best Practice)
If you’re working on any real project, a virtual environment is the way to go. It keeps your project dependencies isolated so they don’t interfere with each other or your system Python.
Here’s the full workflow:
Step 1: Create the virtual environment
python -m venv myenv
Step 2: Activate it
On Windows:
myenv\Scripts\activate
On macOS/Linux:
source myenv/bin/activate
You’ll see (myenv) appear at the start of your terminal prompt — that tells you the environment is active.
Step 3: Install Matplotlib inside the environment
pip install matplotlib
Step 4: Verify
python -c "import matplotlib; print(matplotlib.__version__)"
Step 5: When you’re done, deactivate
deactivate
Every project I work on gets its own virtual environment. It saves a lot of headaches down the road with conflicting package versions.
How to Verify Matplotlib Is Installed
Run this in your terminal (not inside Python — just directly in the command line):
python -c "import matplotlib; print(matplotlib.__version__)"
If Matplotlib is installed, you’ll see the version number. Something like:
3.10.1
You can also check the install location at the same time:
python -c "import matplotlib; print(matplotlib.__version__, matplotlib.__file__)"
Inside a Python shell or Jupyter Notebook, you can also run:
import matplotlib
print(matplotlib.__version__)
Your First Matplotlib Plot (Test It Works)
Once Matplotlib is installed, the best way to confirm everything is working is to actually run a plot. Paste this into a .py file or Jupyter Notebook and run it:
import matplotlib.pyplot as plt
# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# Create the plot
plt.plot(x, y, marker='o', color='steelblue', linewidth=2, markersize=8)
# Add labels and title
plt.title("My First Matplotlib Plot", fontsize=14)
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
# Add grid lines for readability
plt.grid(True, linestyle='--', alpha=0.6)
# Display the plot
plt.show()
If a window pops up showing a clean line chart, Matplotlib is fully working. If the plot doesn’t appear, see the error fixes below.
Common Matplotlib Installation Errors & Fixes
This section is what most tutorials skip. Here are the errors I see most often, and how to actually fix them:
| Error | Likely Cause | Fix |
|---|---|---|
ModuleNotFoundError: No module named 'matplotlib' | Installed in the wrong Python | Use python -m pip install matplotlib instead of just pip install matplotlib |
pip: command not found | pip not installed or not in PATH | Run python -m ensurepip --upgrade |
ImportError: DLL load failed (Windows) | Missing Visual C++ Redistributable | Download and install from Microsoft’s official page |
| Plot window opens but is blank | plt.show() missing | Add plt.show() at the end of your script |
| Plot doesn’t appear at all in terminal | Backend issue | Try import matplotlib; matplotlib.use('TkAgg') before importing pyplot |
ERROR: Failed building wheel | Outdated pip or missing wheel package | Run python -m pip install --upgrade pip wheel setuptools then try again |
SSL Certificate verification failed | Corporate firewall or outdated certs | Try pip install matplotlib --trusted-host pypi.org --trusted-host files.pythonhosted.org |
| Version conflict with NumPy | Incompatible package versions | Run pip install matplotlib --upgrade or create a fresh virtual environment |
The single most common mistake: Running pip install matplotlib when you have multiple Python versions installed. Python might be 3.12, but pip might be pointing to an older Python 2.x. Always use python -m pip install matplotlib — this guarantees pip installs into the Python you’re actually using.
pip vs conda vs venv — Which Should You Use?
Here’s my quick take on when to use each method:
| Method | Best For | Pros | Cons |
|---|---|---|---|
python -m pip install matplotlib | Quick start, any OS | Fast, universal, always gets latest version | Can conflict with system Python packages |
conda install matplotlib | Data science projects with Anaconda | Manages all scientific dependencies together | Requires Anaconda or Miniconda installed |
conda install -c conda-forge matplotlib | Conda users who want the freshest release | Most up-to-date conda version | Same as above |
| Virtual env + pip | Any serious project | Fully isolated, no conflicts | Requires an extra activation step |
sudo apt-get install python3-matplotlib | Linux system scripting | No pip needed | Often installs an older Matplotlib version |
My recommendation: for any project beyond quick experimentation, use a virtual environment with pip. It’s the most reliable setup and works the same way across Windows, macOS, and Linux.
How to Upgrade or Uninstall Matplotlib
Upgrade to the latest version:
pip install --upgrade matplotlib
Check what version you have before upgrading:
pip show matplotlib
This shows you the version, install location, and dependencies, very useful for debugging.
Uninstall Matplotlib completely:
pip uninstall matplotlib
You’ll be asked to confirm. Press y and hit Enter.
If you need a specific version (for compatibility with an older project):
pip install matplotlib==3.8.0
FAQ
How do I know if Matplotlib is already installed?
Run python -c “import matplotlib; print(matplotlib.__version__)” in your terminal. If you see a version number, it’s installed. If you get a ModuleNotFoundError, it’s not.
Can I install Matplotlib without pip?
Yes. On Linux, use your system package manager (apt-get, dnf, pacman). On Anaconda, use conda install matplotlib. You can also install from source, but that’s only needed in rare cases.
How do I install a specific version of Matplotlib?
Use pip install matplotlib==X.X.X — for example, pip install matplotlib==3.7.2.
Why does my plot not show up?
Make sure you have plt.show() at the end of your script. If you’re in Jupyter Notebook, you may not need plt.show() — just run the cell. If the window still doesn’t appear, there may be a backend issue. Try adding import matplotlib; matplotlib.use(‘TkAgg’) before your pyplot import.
Does Matplotlib work with Python 3.12?
Yes. Matplotlib fully supports Python 3.9 through 3.13. Always use the latest Python 3.x version for best compatibility.
How do I completely remove and reinstall Matplotlib?
Uninstall with pip uninstall matplotlib, delete the Matplotlib cache from your config directory, then reinstall with python -m pip install matplotlib.
You may read:
- Save Matplotlib Table as PDF in Python
- Flip Y-Axis Label in Matplotlib using Python
- Invert the Y-Axis in Matplotlib imshow
- Create Two Y Axes Bar Plot in Matplotlib

Bijay Kumar is an experienced Python and AI professional who enjoys helping developers learn modern technologies through practical tutorials and examples. His expertise includes Python development, Machine Learning, Artificial Intelligence, automation, and data analysis using libraries like Pandas, NumPy, TensorFlow, Matplotlib, SciPy, and Scikit-Learn. At PythonGuides.com, he shares in-depth guides designed for both beginners and experienced developers. More about us.