Environment variables#

HOME#

The user's home directory. On Linux, ~ is shorthand for HOME.

MPLBACKEND#

This optional variable can be set to choose the Matplotlib backend. See What is a backend?.

MPLCONFIGDIR#

This is the directory used to store user customizations to Matplotlib, as well as some caches to improve performance. If MPLCONFIGDIR is not defined, HOME/.config/matplotlib and HOME/.cache/matplotlib are used on Linux, and HOME/.matplotlib on other platforms, if they are writable. Otherwise, the Python standard library's tempfile.gettempdir is used to find a base directory in which the matplotlib subdirectory is created.

MPLSETUPCFG#

This optional variable can be set to the full path of a mplsetup.cfg configuration file used to customize the Matplotlib build. By default, a mplsetup.cfg file in the root of the Matplotlib source tree will be read. Supported build options are listed in mplsetup.cfg.template.

PATH#

The list of directories searched to find executable programs.

PYTHONPATH#

The list of directories that are added to Python's standard search list when importing packages and modules.

QT_API#

The Python Qt wrapper to prefer when using Qt-based backends. See the entry in the usage guide for more information.

Setting environment variables in Linux and macOS#

To list the current value of PYTHONPATH, which may be empty, try:

echo $PYTHONPATH

The procedure for setting environment variables in depends on what your default shell is. Common shells include bash and csh. You should be able to determine which by running at the command prompt:

echo $SHELL

To create a new environment variable:

export PYTHONPATH=~/Python  # bash/ksh
setenv PYTHONPATH ~/Python  # csh/tcsh

To prepend to an existing environment variable:

export PATH=~/bin:${PATH}  # bash/ksh
setenv PATH ~/bin:${PATH}  # csh/tcsh

The search order may be important to you, do you want ~/bin to be searched first or last? To append to an existing environment variable:

export PATH=${PATH}:~/bin  # bash/ksh
setenv PATH ${PATH}:~/bin  # csh/tcsh

To make your changes available in the future, add the commands to your ~/.bashrc or ~/.cshrc file.

Setting environment variables in Windows#

Open the Control Panel (Start ‣ Control Panel), start the System program. Click the Advanced tab and select the Environment Variables button. You can edit or add to the User Variables.