<divid="unreleased-message"> You are reading an old version of the documentation (v2.0.0). For the latest version see <ahref="/stable/">https://matplotlib.org/stable/</a></div>
<spanid="virtualenv-faq"></span><h1>Working with Matplotlib in Virtual environments<aclass="headerlink" href="#working-with-matplotlib-in-virtual-environments" title="Permalink to this headline">¶</a></h1>
<divclass="contents topic" id="contents">
<pclass="topic-title first">Contents</p>
<ulclass="simple">
<li><aclass="reference internal" href="#working-with-matplotlib-in-virtual-environments" id="id1">Working with Matplotlib in Virtual environments</a><ul>
<spanid="virtualenv-introduction"></span><h2>Introduction<aclass="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>When running <codeclass="xref py py-mod docutils literal"><spanclass="pre">matplotlib</span></code> in a
<aclass="reference external" href="https://virtualenv.pypa.io/en/latest/">virtual environment</a> you may discover
a few issues. <codeclass="xref py py-mod docutils literal"><spanclass="pre">matplotlib</span></code> itself has no issue with virtual environments.
However, the GUI frameworks that <codeclass="xref py py-mod docutils literal"><spanclass="pre">matplotlib</span></code> uses for interactive
figures have some issues with virtual environments. Everything below assumes
some familiarity with the Matplotlib backends as found in <aclass="reference internal" href="usage_faq.html#what-is-a-backend"><spanclass="std std-ref">What is a
backend?</span></a>.</p>
<p>If you only use the <codeclass="docutils literal"><spanclass="pre">IPython/Jupyter</span><spanclass="pre">Notebook</span></code>‘s <codeclass="docutils literal"><spanclass="pre">inline</span></code> and <codeclass="docutils literal"><spanclass="pre">notebook</span></code>
backends and non interactive backends you should not have any issues and can
ignore everything below.</p>
<p>If you are using Matplotlib on OSX you may also want to consider the
<h2>GUI Frameworks<aclass="headerlink" href="#gui-frameworks" title="Permalink to this headline">¶</a></h2>
<p>Interactive Matplotlib relies heavily on the interaction with external GUI
frameworks.</p>
<p>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:</p>
<ulclass="simple">
<li>The <codeclass="docutils literal"><spanclass="pre">TKAgg</span></code> backend doesn’t require any external dependencies and is
normally always available.</li>
<li>The <codeclass="docutils literal"><spanclass="pre">QT4</span></code> framework <codeclass="docutils literal"><spanclass="pre">PySide</span></code> is pip installable.</li>
<li><codeclass="docutils literal"><spanclass="pre">PYQT5</span></code> is pip installable on Python 3.5.</li>
</ul>
<p>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.</p>
<p>One often suggested solution is to use the <codeclass="docutils literal"><spanclass="pre">--system-site-packages</span></code> option
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 <aclass="reference external" href="https://virtualenvwrapper.readthedocs.io/">virtualenvwrapper</a>
this can be toggled with the <codeclass="docutils literal"><spanclass="pre">toggleglobalsitepackages</span></code> command.</p>
<p>Alternatively, you can manually symlink the GUI frameworks into the environment.
I.e. to use PyQt5, you should symlink <codeclass="docutils literal"><spanclass="pre">PyQt5</span></code> and <codeclass="docutils literal"><spanclass="pre">sip</span></code> from your system
site packages directory into the environment taking care that the environment
and the systemwide install use the same python version.</p>