Unable to import matplotlib.pyplot with latest conda
<p>I am running Conda version 4.2.9 with Python 2.7.12, I have confirmed this bug with a fresh conda environment and only the matplotlib package</p>

<p>My problem occurs when I try to import matplotlib.pyplot:</p>

<pre><code>&gt;&gt;&gt; import matplotlib.pyplot
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/home/me/anaconda2/envs/snowflake/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in &lt;module&gt;
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/home/me/anaconda2/envs/snowflake/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/home/me/anaconda2/envs/snowflake/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 16, in &lt;module&gt;
    from .backend_qt5 import QtCore
  File "/home/me/anaconda2/envs/snowflake/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 31, in &lt;module&gt;
    from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, __version__
  File "/home/me/anaconda2/envs/snowflake/lib/python2.7/site-packages/matplotlib/backends/qt_compat.py", line 137, in &lt;module&gt;
    from PyQt4 import QtCore, QtGui
ImportError: No module named PyQt4
</code></pre>

<p>I have googled this issue extensively and see that there are some temporary solutions, however, I don't know how to use one of them and the other one doesn't work for me.</p>

<p>One solution was to set the backend for matplotlib manually like so:</p>

<pre><code>&gt;&gt;&gt; import matplotlib
&gt;&gt;&gt; matplotlib.use('Qt5Agg')
&gt;&gt;&gt; import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/home/me/anaconda2/envs/snowflake/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in &lt;module&gt;
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/home/me/anaconda2/envs/snowflake/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/home/me/anaconda2/envs/snowflake/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 16, in &lt;module&gt;
    from .backend_qt5 import QtCore
  File "/home/me/anaconda2/envs/snowflake/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 31, in &lt;module&gt;
    from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, __version__
  File "/home/me/anaconda2/envs/snowflake/lib/python2.7/site-packages/matplotlib/backends/qt_compat.py", line 137, in &lt;module&gt;
    from PyQt4 import QtCore, QtGui
ImportError: No module named PyQt4
</code></pre>

<p>As you can see this failed for me. The other solution was to use a patch (<a href="https://github.com/ContinuumIO/anaconda-issues/issues/1068" rel="nofollow">sourced from this thread</a>). Unfortunately I do not know how to use this patch or how to "pin pyqt to 4.11". Can anyone help?</p>

<p>Pinning packages is explained <a href="http://conda.pydata.org/docs/faq.html#pinning-packages" rel="nofollow">here</a>.</p>

<p><a href="https://github.com/ContinuumIO/anaconda-recipes/blob/master/matplotlib/rctmp_pyside.patch" rel="nofollow">The patch</a> is so small you can apply it by hand. Look for your <a href="http://matplotlib.org/users/customizing.html#the-matplotlibrc-file" rel="nofollow">matplotlibrc</a> file (probably <code>.config/matplotlib/matplotlibrc</code>), and set the default backend to Qt5Agg by editing the following lines:</p>

<pre><code>backend      : Qt5Agg
backend.qt5  : PyQt5
</code></pre>

<p>However, since you already have <code>use("Qt5Agg")</code> in your program, which overrides the rcfile, I don't think this will help.</p>

<p>I think your issue is caused by having a <code>QT_API</code> environment variable that still is set to <code>PyQt4</code> (or <code>PySide</code>). Check this, for instance, by adding <code>import os; print(os.environ.get('QT_API'))</code> to your program. If this is the case, add the line <code>export QT_API=PyQt5</code> to your <code>.bashrc</code> (assuming you run Linux).</p>

python matplotlib pyqt conda