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

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.

Read: modulenotfounderror: no module named ‘matplotlib’

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:

python -m pip install -U pip
python -m pip install -U matplotlib [--prefer-binary]

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:

import matplotlib
matplotlib.__version__

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:
sudo apt-get install python3-matplotlib
  • For Red Hat you can use the following command:
sudo yum install python3-matplotlib
  • For Fedora you can use the following command:
sudo dnf install python3-matplotlib
  • For Arch you can use the following command:
sudo pacman -S python-matplotlib

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:
python -m venv <directory_path>

The above command creates a virtual environment (a dedicated directory) in the location <directory_path>.

  • Activate the environment created:
source <directory_path>/bin/activate

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.

git clone https://github.com/matplotlib/matplotlib.git
  • 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:
python -m pip install -ve

Now, you can import the matplotlib package and use it in your development environment.

Read: Slicing string in Python

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:

python -m pip install -U pip        # Update the pip package manager
python -m pip install -U matplotlib [--prefer-binary]

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:

import matplotlib
matplotlib.__version__

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:
python -m venv <directory_path>

The above command creates a virtual environment (a dedicated directory) in the location <directory_path>.

  • Activate the environment created:
source <directory_path>/bin/activate.bat

# Note that, this command was different for Linux distribution

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:
# Retrieve the latest version of matplotlib from the git source

git clone https://github.com/matplotlib/matplotlib.git


# Install matplotlib in the editable mode

python -m pip install -ve

The above commands are already discussed in the previous topic.

Read: Python NumPy Random

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:

python -m pip install -U pip        # Update the pip package manager
python -m pip install -U matplotlib [--prefer-binary]

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:

import matplotlib
matplotlib.__version__

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.

# You can see that all the steps are same, as done for the Linux

# Creating a development environment
python -m venv <directory_path>


# Activate the created environment
source <directory_path>/bin/activate


# Retrieve the latest version of matplotlib from the git source
git clone https://github.com/matplotlib/matplotlib.git


# Install matplotlib in the editable mode
python -m pip install -ve

Read: Python Tkinter OptionMenu

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:

conda install matplotlib

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.

conda install -c conda-forge matplotlib

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