Install Matplotlib using pip, the Python package manager
The fastest way to install Matplotlib is through pip, which comes built into Python 3.4 and newer. Open your terminal or command prompt and run a single command — pip will download Matplotlib and all its dependencies automatically.
Before you install, make sure Python is already on your machine. Type python --version or python3 --version into your terminal to check. If nothing appears, you need to install Python first from python.org. Once Python is confirmed, the pip installation takes about two minutes on most connections.
Key Takeaways
- The command pip install matplotlib installs Matplotlib and its required dependencies in one step on Windows, Mac, and Linux.
- If you use multiple Python versions, specify the version with pip3 install matplotlib to ensure it goes to Python 3.
- Virtual environments let you install Matplotlib for one project without affecting others, using python -m venv before pip install.
- Conda, the package manager included with Anaconda Python, is an alternative to pip that handles dependencies differently and works well on all operating systems.
- After installation, test it by opening Python and typing import matplotlib — if no error appears, the installation worked.
Step-by-step installation on Windows
Open Command Prompt by pressing Windows key + R, typing cmd, and pressing Enter. Type the command pip install matplotlib and press Enter. Pip will download Matplotlib and display progress in the terminal. When it finishes, you will see "Successfully installed matplotlib" followed by a version number.
If you get an error saying "pip is not recognized", Python may not be in your system path. Reinstall Python from python.org and check the box that says "Add Python to PATH" during setup. After reinstalling, close and reopen Command Prompt, then run the pip command again.
Step-by-step installation on Mac and Linux
Open Terminal and type pip3 install matplotlib. The 3 ensures the package goes to Python 3 rather than the older Python 2 that may still be on your system. Press Enter and wait for the download to finish. You may be asked to enter your password — this is normal and required to install system-wide packages.
If you see a permission error even after entering your password, you can install just for your user account instead by typing pip3 install --user matplotlib. This avoids needing administrator access and is often safer for development work.
Using a virtual environment to keep projects separate
A virtual environment is a folder on your computer that holds its own copy of Python and its packages. This way, one project can use Matplotlib version 3.5 while another uses version 3.8, without them interfering. Virtual environments are optional but recommended if you work on multiple projects.
To create a virtual environment, open your terminal in the folder where your project lives and type python -m venv myenv. Replace myenv with any name you want. Then activate it by typing source myenv/bin/activate on Mac or Linux, or myenv\Scripts\activate on Windows. Your terminal prompt will change to show the environment is active. Now type pip install matplotlib — this time it installs only inside that folder, not system-wide.
Installing Matplotlib with Anaconda or Miniconda
Conda is an alternative package manager that comes with Anaconda Python. If you already have Anaconda or Miniconda installed, you can use conda instead of pip. Open Anaconda Prompt (on Windows) or your regular terminal (on Mac or Linux) and type conda install matplotlib. Conda often handles complex dependencies more smoothly than pip, especially on older machines.
Anaconda is larger to download than standard Python but includes many data science packages pre-installed. Miniconda is smaller and lets you install only what you need. If you do not have either, you can download Miniconda from conda.io and follow the installer. After installation, conda commands work the same way as pip commands.
Verify the installation worked
After installation finishes, test it by opening Python. Type python or python3 in your terminal to start the Python interpreter. You will see a prompt that looks like >>>. Type import matplotlib and press Enter. If nothing happens and you see the prompt again, the installation worked. If you see an error message, something went wrong.
A more complete test is to type import matplotlib.pyplot as plt and then plt.plot([1, 2, 3]) followed by plt.show(). A window should open showing a simple line graph. Close the window and type exit() to leave Python. This confirms Matplotlib can create and display plots.
Troubleshooting common installation problems
If pip says "command not found" or "is not recognized", Python is not in your system path. On Windows, reinstall Python and check "Add Python to PATH". On Mac or Linux, you may need to use pip3 instead of pip, or check that Python 3 is actually installed by typing which python3.
If installation starts but fails partway through, you may have a network issue or a corrupted download. Try running pip install --upgrade pip first to update pip itself, then try pip install matplotlib again. If it fails repeatedly, try pip install --no-cache-dir matplotlib to skip cached files that might be corrupted.
If you see "permission denied" on Mac or Linux, try pip install --user matplotlib to install for your user account only. If you are in a virtual environment and still see permission errors, make sure the environment is activated — your terminal prompt should show the environment name in parentheses.
Frequently Asked Questions
Do I need to install anything else before Matplotlib?
No. Python 3.4 or newer is the only requirement. Matplotlib's installer automatically downloads and installs its dependencies, which include NumPy and other libraries it needs to run. You do not need to install these separately.
What is the difference between pip and conda?
Both install packages, but they handle dependencies differently. Pip is simpler and comes with Python. Conda is part of Anaconda and often resolves complex dependency conflicts better, especially for scientific packages. For most users, pip is fine. If you already use Anaconda, conda is convenient.
Can I install multiple versions of Matplotlib at the same time?
Not in the same Python installation. But you can use virtual environments — create one for each version and activate whichever you need. This is the standard way to work with different package versions across projects.
Why does the installation take so long?
Matplotlib depends on several other packages like NumPy, Pillow, and others. Pip downloads and installs all of them, which can take a minute or two depending on your internet speed and computer. This is normal and only happens once per Python installation.
How do I update Matplotlib after it is already installed?
Type pip install --upgrade matplotlib or pip install -U matplotlib. This downloads the newest version and replaces the old one. If you use conda, type conda update matplotlib instead.