You are reading an old version of the documentation (v3.1.0). For the latest version see https://matplotlib.org/stable/
Version 3.1.0
matplotlib
Fork me on GitHub

Working with Matplotlib in Virtual environmentsΒΆ

While Matplotlib itself runs fine in a virtual environment (venv), some of the GUI frameworks that Matplotlib uses for interactive figures are tricky to install in a venv. Everything below assumes some familiarity with the Matplotlib backends as found in What is a backend?.

If you only use the IPython and Jupyter Notebook's inline and notebook backends, or non-interactive backends, you should not have any issues and can ignore everything below.

Likewise, the Tk framework (TkAgg backend) does not require any external dependencies and is normally always available. On certain Linux distributions, a package named python-tk (or similar) needs to be installed.

Otherwise, the situation (at the time of writing) is as follows:

framework bindings pip-installable? conda or conda-forge-installable?
Qt5 PyQt5 yes yes
Qt5 PySide2 yes yes
Qt4 PyQt4 no yes
Qt4 PySide OSX and Windows yes
GTK3 PyGObject yes [1] Linux and OSX
wxWidgets wxPython yes [2] yes
[1]No wheels available, see https://pygobject.readthedocs.io/en/latest/devguide/dev_environ.html for build instructions.
[2]OSX and Windows wheels available on PyPI. Linux wheels available but not on PyPI, see https://wxpython.org/pages/downloads/.

For cases where the framework is not installable in a venv, it needs to be installed in the global (system) site-packages, and then made available from within the venv. This can be achieved by either of the following methods (in all cases, the system-wide Python and the venv Python must be of the same version):

  • vext allows controlled access from within the venv to specific system-wide packages. A specific package needs to be installed for each framework, e.g. vext.pyqt5, etc. It is recommended to use vext>=0.7.0 as earlier versions misconfigure the logging system.
  • Using the --system-site-packages option when creating an environment adds all system-wide packages to the virtual environment. However, this breaks the isolation between the virtual environment and the system install. Among other issues it results in hard to debug problems with system packages shadowing the environment packages. If you use virtualenv (rather than the stdlib's venv) together with virtualenvwrapper, this can be toggled with the toggleglobalsitepackages command.

If you are using Matplotlib on OSX, you may also want to consider the OSX framework FAQ.