The fastest way to install Matplotlib
The standard way to install Matplotlib is through pip, Python's package manager. Open your terminal or command prompt and type one line: pip install matplotlib. That command downloads Matplotlib and all the libraries it needs, then installs them on your computer. On most systems, the whole process takes under a minute.
If you have multiple Python versions installed, you may need to specify which one: pip3 install matplotlib uses Python 3 specifically. After installation finishes, you can test it by opening Python and typing import matplotlib.pyplot. If no error appears, the installation worked.
Key Takeaways
- The pip command pip install matplotlib is the standard installation method and works on Windows, Mac, and Linux without extra steps.
- If you use Anaconda instead of standard Python, use conda install matplotlib in the Anaconda prompt rather than pip.
- On Mac with Apple Silicon (M1, M2, M3 chips), you may need to install from conda or use a specific pip command to avoid compatibility issues.
- After installation, test it by opening Python and typing import matplotlib.pyplot — if no error appears, Matplotlib is ready to use.
- If pip is not found, you may need to install Python again or add Python to your system PATH.
Installation on Windows
On Windows, open Command Prompt (search "cmd" in the Start menu) or PowerShell and type pip install matplotlib. You should see text scrolling as pip downloads the package and its dependencies. Wait for the prompt to return and show "Successfully installed" before closing the window.
If you get an error saying "pip is not recognized", Python may not be in your system PATH. The easiest fix is to uninstall Python completely, then reinstall it from python.org. During installation, check the box that says "Add Python to PATH" before clicking Install. After reinstalling, open a new Command Prompt and try the pip command again.
Installation on Mac
On Mac, open Terminal (find it in Applications > Utilities) and type pip3 install matplotlib. The 3 ensures you are using Python 3, which is the standard on modern Macs. Wait for the installation to complete.
If you have an Apple Silicon Mac (M1, M2, M3, or later), the standard pip command sometimes installs a version that runs slowly. For better performance, use conda install matplotlib instead if you have Anaconda installed. If you do not have Anaconda, you can install it from anaconda.com, then use the conda command. Alternatively, you can use pip install --upgrade --force-reinstall --no-cache-dir matplotlib, which forces pip to build the package for your specific chip.
Installation on Linux
On Linux, open a terminal and type pip3 install matplotlib. Most Linux distributions come with pip already installed. If you get a "command not found" error, install pip first: on Ubuntu or Debian, run sudo apt-get install python3-pip. On Fedora or Red Hat systems, run sudo dnf install python3-pip. Then run the matplotlib install command.
Some Linux users prefer to install through their system package manager instead of pip. On Ubuntu, you can type sudo apt-get install python3-matplotlib. This method integrates with your system updates but may install an older version of Matplotlib. For the newest version, pip is the better choice.
Using Anaconda or Miniconda instead of pip
If you installed Python through Anaconda or Miniconda, use the conda package manager instead of pip. Open the Anaconda Prompt (on Windows, search for it in the Start menu; on Mac or Linux, open Terminal and type conda to check if it is available). Then type conda install matplotlib.
Conda often installs packages faster than pip because it pre-builds them for your system. If you are working on a team or managing multiple projects, conda also makes it easier to create separate environments where different projects can have different package versions without conflicts. For most beginners, though, pip is simpler and works just as well.
Checking your installation and fixing common errors
After installation, verify that Matplotlib works by opening Python and running these three lines:
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [1, 4, 9]) plt.show()
A window should pop up showing a straightforward line graph. If it does, Matplotlib is installed correctly. If you see an error like "ModuleNotFoundError: No module named 'matplotlib'", the installation did not complete. Try running the pip install command again, and watch for any error messages during installation.
If you see "No module named 'tkinter'" on Linux, Matplotlib needs an extra package to display graphs. On Ubuntu or Debian, run sudo apt-get install python3-tk. On Fedora, run sudo dnf install python3-tkinter. Then try the test code again.
Upgrading Matplotlib to a newer version
If you already have Matplotlib installed but want the latest version, use pip install --upgrade matplotlib. This command downloads and installs the newest release without removing your old one. The upgrade usually takes less than a minute.
You can check which version you have by opening Python and typing import matplotlib; print(matplotlib.__version__). This prints the version number. If you need a specific older version for compatibility with other code, you can install it with pip install matplotlib==3.5.2 (replacing 3.5.2 with the version you need).
Frequently Asked Questions
Do I need to install anything else before installing Matplotlib?
No. Matplotlib installs all its own dependencies automatically when you run pip install. You only need Python itself, which you should already have if you are reading this. If Python is not installed, read it from python.org and run the installer.
Why does the installation fail on my Mac with Apple Silicon?
Standard pip sometimes tries to install a version built for Intel chips, which runs slowly on Apple Silicon. Use conda install matplotlib instead, or use the force-reinstall command mentioned in the Mac section. Both methods install a version optimized for your chip.
Can I install Matplotlib in a virtual environment?
Yes, and it is a good practice. Create a virtual environment with python -m venv myenv, set up it with source myenv/bin/set up (Mac/Linux) or myenv\Scripts\set up (Windows), then run pip install matplotlib. This keeps Matplotlib isolated from other projects on your computer.
What if I get a permission error when installing on Mac or Linux?
Do not use sudo with pip. Instead, use pip install --user matplotlib, which installs Matplotlib in your user folder. Using sudo can break your Python installation. If you already used sudo, reinstalling Python is the safest fix.
How do I uninstall Matplotlib if I need to?
Type pip uninstall matplotlib and answer yes when prompted. This removes Matplotlib but leaves Python and other packages intact. You can reinstall it anytime with pip install matplotlib.