Installing¶
There are many different ways to install matplotlib, and the best way depends on what operating system you are using, what you already have installed, and how you want to use it. To avoid wading through all the details (and potential complications) on this page, there are several convenient options.
Installing pre-built packages¶
Most platforms : scientific Python distributions¶
The first option is to use one of the pre-packaged python distributions that already provide matplotlib built-in. The Continuum.io Python distribution (Anaconda or miniconda) and the Enthought distribution (Canopy) are both excellent choices that “just work” out of the box for Windows, OSX and common Linux platforms. Both of these distributions include matplotlib and lots of other useful tools.
Linux : using your package manager¶
If you are on Linux, you might prefer to use your package manager. matplotlib is packaged for almost every major Linux distribution.
- Debian / Ubuntu : sudo apt-get install python-matplotlib
- Fedora / Redhat : sudo yum install python-matplotlib
Mac OSX : using pip¶
If you are on Mac OSX you can probably install matplotlib binaries using the standard Python installation program pip. See Installing OSX binary wheels .
Windows¶
If you don’t already have Python installed, we recommend using one of the scipy-stack compatible Python distributions such as WinPython, Python(x,y), Enthought Canopy, or Continuum Anaconda, which have matplotlib and many of its dependencies, plus other useful packages, preinstalled.
For standard Python installations, install matplotlib using pip:
In case Python 2.7 or 3.4 are not installed for all users, the Microsoft Visual C++ 2008 ( 64 bit or 32 bit for Python 2.7) or Microsoft Visual C++ 2010 ( 64 bit or 32 bit for Python 3.4) redistributable packages need to be installed.
Matplotlib depends on Pillow for reading and saving JPEG, BMP, and TIFF image files. Matplotlib requires MiKTeX and GhostScript for rendering text with LaTeX. FFmpeg, avconv, mencoder, or ImageMagick are required for the animation module.
The following backends should work out of the box: agg, tkagg, ps, pdf and svg. For other backends you may need to install pycairo, PyQt4, PyQt5, PySide, wxPython, PyGTK, Tornado, or GhostScript.
TkAgg is probably the best backend for interactive use from the standard Python shell or IPython. It is enabled as the default backend for the official binaries. GTK3 is not supported on Windows.
The Windows wheels ( *.whl ) on the PyPI download page do not contain test data or example code. If you want to try the many demos that come in the matplotlib source distribution, download the *.tar.gz file and look in the examples subdirectory. To run the test suite, copy the lib\matplotlib\tests and lib\mpl_toolkits\tests directories from the source distribution to sys.prefix\Lib\site-packages\matplotlib and sys.prefix\Lib\site-packages\mpl_toolkits respectively, and install nose, mock, Pillow, MiKTeX, GhostScript, ffmpeg, avconv, mencoder, ImageMagick, and Inkscape.
Installing from source¶
If you are interested in contributing to matplotlib development, running the latest source code, or just like to build everything yourself, it is not difficult to build matplotlib from source. Grab the latest tar.gz release file from the PyPI files page, or if you want to develop matplotlib or just need the latest bugfixed version, grab the latest git version Source install from git .
The standard environment variables CC , CXX , PKG_CONFIG are respected. This means you can set them if your toolchain is prefixed. This may be used for cross compiling.
Once you have satisfied the requirements detailed below (mainly python, numpy, libpng and freetype), you can build matplotlib:
We provide a setup.cfg file that goes with setup.py which you can use to customize the build process. For example, which default backend to use, whether some of the optional libraries that matplotlib ships with are installed, and so on. This file will be particularly useful to those packaging matplotlib.
If you have installed prerequisites to nonstandard places and need to inform matplotlib where they are, edit setupext.py and add the base dirs to the basedir dictionary entry for your sys.platform . e.g., if the header to some required library is in /some/path/include/someheader.h , put /some/path in the basedir list for your platform.
Build requirements¶
These are external packages which you will need to install before installing matplotlib. If you are building on OSX, see Building on OSX . If you are building on Windows, see Building on Windows . If you are installing dependencies with a package manager on Linux, you may need to install the development packages (look for a “-dev” postfix) in addition to the libraries themselves.
Required Dependencies¶
Optional GUI framework¶
These are optional packages which you may want to install to use matplotlib with a user interface toolkit. See What is a backend? for more details on the optional matplotlib backends and the capabilities they provide.
tk 8.3 or later, not 8.6.0 or 8.6.1
The TCL/Tk widgets library used by the TkAgg backend.
Versions 8.6.0 and 8.6.1 are known to have issues that may result in segfaults when closing multiple windows in the wrong order.
pyqt 4.4 or later The Qt4 widgets library python wrappers for the Qt4Agg backend pygtk 2.4 or later The python wrappers for the GTK widgets library for use with the GTK or GTKAgg backend wxpython 2.8 or later The python wrappers for the wx widgets library for use with the WX or WXAgg backend
Optional external programs¶
Optional dependencies¶
Required libraries that ship with matplotlib¶
Building on Linux¶
It is easiest to use your system package manager to install the dependencies.
If you are on Debian/Ubuntu, you can get all the dependencies required to build matplotlib with:
If you are on Fedora/RedHat, you can get all the dependencies required to build matplotlib by first installing yum-builddep and then running:
This does not build matplotlib, but it does get the install the build dependencies, which will make building from source easier.
Building on OSX¶
The build situation on OSX is complicated by the various places one can get the libpng and freetype requirements (darwinports, fink, /usr/X11R6) and the different architectures (e.g., x86, ppc, universal) and the different OSX version (e.g., 10.4 and 10.5). We recommend that you build the way we do for the OSX release: get the source from the tarball or the git repository and follow the instruction in README.osx .
Building on Windows¶
The Python shipped from http://www.python.org is compiled with Visual Studio 2008 for versions before 3.3, Visual Studio 2010 for 3.3 and 3.4, and Visual Studio 2015 for 3.5. Python extensions are recommended to be compiled with the same compiler.
Since there is no canonical Windows package manager, the methods for building freetype, zlib, and libpng from source code are documented as a build script at matplotlib-winbuild.
Name already in use
matplotlib / doc / users / installing / index.rst
- Go to file T
- Go to line L
- Copy path
- Copy permalink
- Open with Desktop
- View raw
- Copy raw contents Copy raw contents
Copy raw contents
Copy raw contents
Installing an official release
Matplotlib releases are available as wheel packages for macOS, Windows and Linux on PyPI. Install it using pip :
If this command results in Matplotlib being compiled from source and there’s trouble with the compilation, you can add —prefer-binary to select the newest version of Matplotlib for which there is a precompiled wheel for your OS and Python.
The following backends work out of the box: Agg, ps, pdf, svg
Python is typically shipped with tk bindings which are used by TkAgg.
For support of other GUI frameworks, LaTeX rendering, saving animations and a larger selection of file formats, you can install :ref:`optional_dependencies` .
Various third-parties provide Matplotlib for their environments.
Matplotlib is available both via the anaconda main channel
as well as via the conda-forge community channel
Matplotlib is part of major Python distributions:
Linux package manager
If you are using the Python version that comes with your Linux distribution, you can install Matplotlib via your package manager, e.g.:
- Debian / Ubuntu: sudo apt-get install python3-matplotlib
- Fedora: sudo dnf install python3-matplotlib
- Red Hat: sudo yum install python3-matplotlib
- Arch: sudo pacman -S python-matplotlib
Installing a nightly build
Matplotlib makes nightly development build wheels available on the scientific-python-nightly-wheels Anaconda Cloud organization. These wheels can be installed with pip by specifying scientific-python-nightly-wheels as the package index to query:
Installing from source
If you are interested in contributing to Matplotlib development, running the latest source code, or just like to build everything yourself, it is not difficult to build Matplotlib from source.
First you need to install the :ref:`dependencies` .
A C compiler is required. Typically, on Linux, you will need gcc , which should be installed using your distribution’s package manager; on macOS, you will need xcode; on Windows, you will need Visual Studio 2015 or later.
For those using Visual Studio, make sure «Desktop development with C++» is selected, and that the latest MSVC, «C++ CMake tools for Windows,» and a Windows SDK compatible with your version of Windows are selected and installed. They should be selected by default under the «Optional» subheading, but are required to build matplotlib from source.
The easiest way to get the latest development version to start contributing is to go to the git repository and run:
If you’re developing, it’s better to do it in editable mode. The reason why is that pytest’s test discovery only works for Matplotlib if installation is done this way. Also, editable mode allows your code changes to be instantly propagated to your library code without reinstalling (though you will have to restart your python process / kernel):
If you’re not developing, it can be installed from the source directory with a simple (just replace the last step):
To run the tests you will need to install some additional dependencies:
Then, if you want to update your Matplotlib at any time, just do:
When you run git pull , if the output shows that only Python files have been updated, you are all set. If C files have changed, you need to run pip install -e . again to compile them.
There is more information on :ref:`using git <using-git>` in the developer docs.
The following instructions in this section are for very custom installations of Matplotlib. Proceed with caution because these instructions may result in your build producing unexpected behavior and/or causing local testing to fail.
If you would like to build from a tarball, grab the latest tar.gz release file from the PyPI files page.
We provide a mplsetup.cfg file which you can use to customize the build process. For example, which default backend to use, whether some of the optional libraries that Matplotlib ships with are installed, and so on. This file will be particularly useful to those packaging Matplotlib.
If you are building your own Matplotlib wheels (or sdists) on Windows, note that any DLLs that you copy into the source tree will be packaged too.
Installing for development
Frequently asked questions
Report a compilation problem
Matplotlib compiled fine, but nothing shows up when I use it
The first thing to try is a :ref:`clean install <clean-install>` and see if that helps. If not, the best way to test your install is by running a script, rather than working interactively from a python shell or an integrated development environment such as :program:`IDLE` which add additional complexities. Open up a UNIX shell or a DOS command prompt and run, for example:
This will give you additional information about which backends Matplotlib is loading, version information, and more. At this point you might want to make sure you understand Matplotlib’s :ref:`configuration <customizing>` process, governed by the :file:`matplotlibrc` configuration file which contains instructions within and the concept of the Matplotlib backend.
If you are still having trouble, see :ref:`reporting-problems` .
How to completely remove Matplotlib
Occasionally, problems with Matplotlib can be solved with a clean installation of the package. In order to fully remove an installed Matplotlib:
- Delete the caches from your :ref:`Matplotlib configuration directory <locating-matplotlib-config-dir>` .
- Delete any Matplotlib directories or eggs from your :ref:`installation directory <locating-matplotlib-install>` .
Which python for OSX?
Apple ships OSX with its own Python, in /usr/bin/python , and its own copy of Matplotlib. Unfortunately, the way Apple currently installs its own copies of NumPy, Scipy and Matplotlib means that these packages are difficult to upgrade (see system python packages). For that reason we strongly suggest that you install a fresh version of Python and use that as the basis for installing libraries such as NumPy and Matplotlib. One convenient way to install Matplotlib with other useful Python software is to use the Anaconda Python scientific software collection, which includes Python itself and a wide range of libraries; if you need a library that is not available from the collection, you can install it yourself using standard methods such as pip. See the Anaconda web page for installation support.
Other options for a fresh Python install are the standard installer from python.org, or installing Python using a general OSX package management system such as homebrew or macports. Power users on OSX will likely want one of homebrew or macports on their system to install open source software packages, but it is perfectly possible to use these systems with another source for your Python binary, such as Anaconda or Python.org Python.
Installing OSX binary wheels
If you are using Python from https://www.python.org, Homebrew, or Macports, then you can use the standard pip installer to install Matplotlib binaries in the form of wheels.
pip is installed by default with python.org and Homebrew Python, but needs to be manually installed on Macports with
Once pip is installed, you can install Matplotlib and all its dependencies with from the Terminal.app command line:
You might also want to install IPython or the Jupyter notebook ( python3 -m pip install ipython notebook ).
How to install matplotlib python
In this Python tutorial, we will discuss How to install matplotlib python with all the required dependencies to use the package in the data visualization in python and we shall also cover the following topics:
- How to install matplotlib python
- How to install matplotlib python ubuntu
- How to install matplotlib python windows
- How to install matplotlib python mac
- How to install matplotlib python conda
- How to install matplotlib python pip
- How to install matplotlib python venv
- How to install matplotlib python3
- How to install matplotlib python2
Table of Contents
How to install matplotlib python
You can install matplotlib library to use it in python in all the three major operating systems commonly used:
- Linux (Ubuntu, redhat, etc.,)
- Windows
- macOS
You can install matplotlib in any of these operating systems either by using the pip command (using the python package manager) to install the released wheel packages available, or by creating a separate virtual environment for matplotlib from other installations of the python and matplotlib, or by using another environment such as anaconda which provides conda as a package manager to install packages.
NOTE –
- Wheel Package is a built-package format for python having the .whl file extension. It contains all the files related to an install package for python with its metadata.
- Virtual Environment is just a named directory for development in python containing all the necessary dependencies and packages installed inside that directory.
- Anaconda is a distribution of python that provides an environment to develop python projects based on scientific researches.
How to install matplotlib python ubuntu
How to install matplotlib python using pip in Linux (Ubuntu)
You can install matplotlib for python in any of the Linux distributions including Ubuntu, by using the python package manager which provides the pip command to install any wheel package released for python. First, make sure that you have installed python and pip in your system. If you don’t have pip installed, first you have to install it, then install the matplotlib using pip. Execute the below commands in the terminal:
In the above commands,
- The first command updates the pip python package manager.
- In the second command, –prefer-binary is optional, if the command excluding the –prefer-binary option fails to install or update the matplotlib package. Then add this option, it selects the newest version according to the precompiled wheel for your operating system and python installed.
You can check if matplotlib is successfully installed on your system by executing the command below in the terminal:
How to install matplotlib python Linux package manager
In Linux, python is pre-installed with the OS distribution, and if you are using that version, then you can install matplotlib by using Linux package manager, Different distributions have different package managers:
- For Debian / Ubuntu you can use the following command:
- For Red Hat you can use the following command:
- For Fedora you can use the following command:
- For Arch you can use the following command:
How to install matplotlib python venv in Linux
You can install matplotlib in a virtual development environment in Linux, by using Python’s virtual environment venv to create a virtual environment. The steps for doing it are given below:
- Creating a virtual environment:
The above command creates a virtual environment (a dedicated directory) in the location <directory_path>.
- Activate the environment created:
The above command activates the development environment. You have to activate the development environment in the shell first, whenever you start working on the matplotlib.
- Retrieve the latest version of matplotlib from the git hosted at https://github.com/matplotlib/matplotlib.git. The below command retrieves the latest sources of matplotlib to the current working directory:
- Now, install matplotlib in the editable (develop) mode as the develop mode let python to import matplotlib from your development environment source directory, that is from the git source, which allows you to import the latest version of matplotlib without re-installing it after any change happens to the source. The below command lets you do it:
Now, you can import the matplotlib package and use it in your development environment.
How to install matplotlib python windows
How to install matplotlib python pip in Windows
You can install matplotlib for python in a Windows OS, by using the python package manager which provides the pip command to install any wheel package released for python.
First, make sure that you have installed python and pip in your system. If you don’t have pip installed, first you have to install it, then install the matplotlib using pip. Execute the below commands in the cmd:
The above command is the same as we have done in Linux distribution in the above topic.
You can check if matplotlib is successfully installed on your system by executing the command below in the cmd:
How to install matplotlib python venv in Windows
You can create a virtual environment in python and configure it for the development of matplotlib in Windows by following the given steps:
- Creating a virtual environment:
The above command creates a virtual environment (a dedicated directory) in the location <directory_path>.
- Activate the environment created:
The above command activates the development environment. You have to activate the development environment in the shell first, whenever you start working on the matplotlib.
- All the steps are same as done for the Linux distribution:
The above commands are already discussed in the previous topic.
How to install matplotlib python mac
How to install matplotlib python pip in macOS
You can install matplotlib for python in a macOS, by using the python package manager which provides the pip command to install any wheel package released for python. First, make sure that you have installed python and pip in your system. If you don’t have pip installed, first you have to install it, then install the matplotlib using pip. Execute the below commands in the cmd:
The above command is also the same as we have done and discussed for the Linux distribution.
You can check if matplotlib is successfully installed on your system by executing the command below in the terminal:
How to install matplotlib python venv in macOS
The steps to create a dedicated development environment for the matplotlib python in macOS are the same as we have done and discussed for the Linux distribution.
How to install matplotlib python conda
Matplotlib is also part of some major Python distributions like an anaconda. So, you can install matplotlib in this distribution of python which provides its environment for the matplotlib. Anaconda is available for all three major operating systems, Linux, Windows, macOS. You can use the package manager provided by anaconda that is conda to install the matplotlib. You must have installed anaconda in your system then you can execute the command below in the cmd /conda prompt/terminal:
The above command will install the matplotlib in the anaconda development environment from the anaconda main channel.
You can install matplotlib from the anaconda community channel also by executing the command below.
How to install matplotlib python3
If you are using python3 then use pip3 in place of pip to install the matplotlib. All the installation process is same as given in above topics, just use pip3 instead.
How to install matplotlib python2
If you are using python2 then use pip to install the matplotlib. All the installation process is same as given in above topics.
You may also like reading the following articles.
In this Python tutorial, we have discussed How to install matplotlib python with all the required dependencies to use the package in the data visualization in python and we have also covered the following topics:
- How to install matplotlib python
- How to install matplotlib python ubuntu
- How to install matplotlib python windows
- How to install matplotlib python mac
- How to install matplotlib python conda
- How to install matplotlib python pip
- How to install matplotlib python venv
- How to install matplotlib python3
- How to install matplotlib python2

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.
Installation#
Matplotlib releases are available as wheel packages for macOS, Windows and Linux on PyPI. Install it using pip :
If this command results in Matplotlib being compiled from source and there’s trouble with the compilation, you can add —prefer-binary to select the newest version of Matplotlib for which there is a precompiled wheel for your OS and Python.
The following backends work out of the box: Agg, ps, pdf, svg
Python is typically shipped with tk bindings which are used by TkAgg.
For support of other GUI frameworks, LaTeX rendering, saving animations and a larger selection of file formats, you can install Optional dependencies .
Third-party distributions#
Various third-parties provide Matplotlib for their environments.
Conda packages#
Matplotlib is available both via the anaconda main channel
as well as via the conda-forge community channel
Python distributions#
Matplotlib is part of major Python distributions:
Linux package manager#
If you are using the Python version that comes with your Linux distribution, you can install Matplotlib via your package manager, e.g.:
Debian / Ubuntu: sudo apt-get install python3-matplotlib
Fedora: sudo dnf install python3-matplotlib
Red Hat: sudo yum install python3-matplotlib
Arch: sudo pacman -S python-matplotlib
Installing a nightly build#
Matplotlib makes nightly development build wheels available on the scipy-wheels-nightly Anaconda Cloud organization. These wheels can be installed with pip by specifying scipy-wheels-nightly as the package index to query:
Installing from source#
If you are interested in contributing to Matplotlib development, running the latest source code, or just like to build everything yourself, it is not difficult to build Matplotlib from source.
First you need to install the Dependencies .
A C compiler is required. Typically, on Linux, you will need gcc , which should be installed using your distribution’s package manager; on macOS, you will need xcode; on Windows, you will need Visual Studio 2015 or later.
For those using Visual Studio, make sure "Desktop development with C++" is selected, and that the latest MSVC, "C++ CMake tools for Windows," and a Windows SDK compatible with your version of Windows are selected and installed. They should be selected by default under the "Optional" subheading, but are required to build matplotlib from source.
The easiest way to get the latest development version to start contributing is to go to the git repository and run:
If you’re developing, it’s better to do it in editable mode. The reason why is that pytest’s test discovery only works for Matplotlib if installation is done this way. Also, editable mode allows your code changes to be instantly propagated to your library code without reinstalling (though you will have to restart your python process / kernel):
If you’re not developing, it can be installed from the source directory with a simple (just replace the last step):
To run the tests you will need to install some additional dependencies:
Then, if you want to update your Matplotlib at any time, just do:
When you run git pull , if the output shows that only Python files have been updated, you are all set. If C files have changed, you need to run pip install -e . again to compile them.
There is more information on using git in the developer docs.
The following instructions in this section are for very custom installations of Matplotlib. Proceed with caution because these instructions may result in your build producing unexpected behavior and/or causing local testing to fail.
If you would like to build from a tarball, grab the latest tar.gz release file from the PyPI files page.
We provide a mplsetup.cfg file which you can use to customize the build process. For example, which default backend to use, whether some of the optional libraries that Matplotlib ships with are installed, and so on. This file will be particularly useful to those packaging Matplotlib.
If you are building your own Matplotlib wheels (or sdists) on Windows, note that any DLLs that you copy into the source tree will be packaged too.
Installing for development#
Frequently asked questions#
Report a compilation problem#
Matplotlib compiled fine, but nothing shows up when I use it#
The first thing to try is a clean install and see if that helps. If not, the best way to test your install is by running a script, rather than working interactively from a python shell or an integrated development environment such as IDLE which add additional complexities. Open up a UNIX shell or a DOS command prompt and run, for example:
This will give you additional information about which backends Matplotlib is loading, version information, and more. At this point you might want to make sure you understand Matplotlib’s configuration process, governed by the matplotlibrc configuration file which contains instructions within and the concept of the Matplotlib backend.
If you are still having trouble, see Getting help .
How to completely remove Matplotlib#
Occasionally, problems with Matplotlib can be solved with a clean installation of the package. In order to fully remove an installed Matplotlib:
Delete any Matplotlib directories or eggs from your installation directory .
OSX Notes#
Which python for OSX?#
Apple ships OSX with its own Python, in /usr/bin/python , and its own copy of Matplotlib. Unfortunately, the way Apple currently installs its own copies of NumPy, Scipy and Matplotlib means that these packages are difficult to upgrade (see system python packages). For that reason we strongly suggest that you install a fresh version of Python and use that as the basis for installing libraries such as NumPy and Matplotlib. One convenient way to install Matplotlib with other useful Python software is to use the Anaconda Python scientific software collection, which includes Python itself and a wide range of libraries; if you need a library that is not available from the collection, you can install it yourself using standard methods such as pip. See the Anaconda web page for installation support.
Other options for a fresh Python install are the standard installer from python.org, or installing Python using a general OSX package management system such as homebrew or macports. Power users on OSX will likely want one of homebrew or macports on their system to install open source software packages, but it is perfectly possible to use these systems with another source for your Python binary, such as Anaconda or Python.org Python.
Installing OSX binary wheels#
If you are using Python from https://www.python.org, Homebrew, or Macports, then you can use the standard pip installer to install Matplotlib binaries in the form of wheels.
pip is installed by default with python.org and Homebrew Python, but needs to be manually installed on Macports with
Once pip is installed, you can install Matplotlib and all its dependencies with from the Terminal.app command line:
You might also want to install IPython or the Jupyter notebook ( python3 -m pip install ipython notebook ).
Checking your installation#
The new version of Matplotlib should now be on your Python "path". Check this at the Terminal.app command line:
You should see something like
where 3.6.0 is the Matplotlib version you just installed, and the path following depends on whether you are using Python.org Python, Homebrew or Macports. If you see another version, or you get an error like
then check that the Python binary is the one you expected by running
If you get a result like /usr/bin/python. , then you are getting the Python installed with OSX, which is probably not what you want. Try closing and restarting Terminal.app before running the check again. If that doesn’t fix the problem, depending on which Python you wanted to use, consider reinstalling Python.org Python, or check your homebrew or macports setup. Remember that the disk image installer only works for Python.org Python, and will not get picked up by other Pythons. If all these fail, please let us know .
© Copyright 2002–2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012–2023 The Matplotlib development team.