matplotlib in a
virtual environment you may discover
a few issues.
matplotlib itself has no issue with virtual environments.
However, the GUI frameworks that
matplotlib uses for interactive
figures have some issues with virtual environments. Everything below assumes
some familiarity with the Matplotlib backends as found in What is a
If you only use the
backends and non interactive backends you should not have any issues and can
ignore everything below.
If you are using Matplotlib on OSX you may also want to consider the OSX framework FAQ.
Interactive Matplotlib relies heavily on the interaction with external GUI frameworks.
Most GUI frameworks are not pip installable. This makes it tricky to install them within a virtual environment. This problem does not exist if you use Conda environments where you can install all Conda supported GUI frameworks directly into the environment. In regular virtualenv environment various workarounds exist. Some of these are given here:
TKAggbackend doesn’t require any external dependencies and is normally always available.
PySideis pip installable.
PYQT5is pip installable on Python 3.5.
Other frameworks are harder to install into a virtual environment. There are at least two possible ways to get access to these in a virtual environment.
One often suggested solution is to use the
to virtualenv when creating an environment. This 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 virtualenvwrapper
this can be toggled with the
Alternatively, you can manually symlink the GUI frameworks into the environment.
I.e. to use PyQt5, you should symlink
sip from your system
site packages directory into the environment taking care that the environment
and the systemwide install use the same python version.