Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matlplotlib qt magic broken? #1451

Closed
nihalf opened this issue Feb 15, 2017 · 13 comments
Closed

matlplotlib qt magic broken? #1451

nihalf opened this issue Feb 15, 2017 · 13 comments
Assignees

Comments

@nihalf
Copy link

nihalf commented Feb 15, 2017

I'm trying to run matlplotlib pyplot interactively using the %matplotlib qt magic. I get the following :

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-6-90119ea04a79> in <module>()
----> 1 get_ipython().magic('matplotlib qt')
      2 plt.plot([1,2,3,4],[1,1.6,4.5, 2])
      3 plt.show()

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
   2156         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2157         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158         return self.run_line_magic(magic_name, magic_arg_s)
   2159 
   2160     #-------------------------------------------------------------------------

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
   2077                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2078             with self.builtin_trap:
-> 2079                 result = fn(*args,**kwargs)
   2080             return result
   2081 

<decorator-gen-104> in matplotlib(self, line)

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/magics/pylab.py in matplotlib(self, line)
     98             print("Available matplotlib backends: %s" % backends_list)
     99         else:
--> 100             gui, backend = self.shell.enable_matplotlib(args.gui)
    101             self._show_matplotlib_backend(args.gui, backend)
    102 

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   2945                 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
   2946 
-> 2947         pt.activate_matplotlib(backend)
   2948         pt.configure_inline_support(self, backend)
   2949 

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py in activate_matplotlib(backend)
    293 
    294     import matplotlib.pyplot
--> 295     matplotlib.pyplot.switch_backend(backend)
    296 
    297     # This must be imported last in the matplotlib series, after

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in switch_backend(newbackend)
    231     matplotlib.use(newbackend, warn=False, force=True)
    232     from matplotlib.backends import pylab_setup
--> 233     _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
    234 
    235 

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/__init__.py in pylab_setup()
     30     # imports. 0 means only perform absolute imports.
     31     backend_mod = __import__(backend_name,
---> 32                              globals(),locals(),[backend_name],0)
     33 
     34     # Things we pull in from all backends

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt4agg.py in <module>()
     16 
     17 
---> 18 from .backend_qt5agg import FigureCanvasQTAggBase as _FigureCanvasQTAggBase
     19 
     20 from .backend_agg import FigureCanvasAgg

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py in <module>()
     14 
     15 from .backend_agg import FigureCanvasAgg
---> 16 from .backend_qt5 import QtCore
     17 from .backend_qt5 import QtGui
     18 from .backend_qt5 import FigureManagerQT

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py in <module>()
     24 
     25 from matplotlib.widgets import SubplotTool
---> 26 import matplotlib.backends.qt_editor.figureoptions as figureoptions
     27 
     28 from .qt_compat import (QtCore, QtGui, QtWidgets, _getSaveFileName,

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py in <module>()
     18 import matplotlib
     19 from matplotlib import cm, markers, colors as mcolors
---> 20 import matplotlib.backends.qt_editor.formlayout as formlayout
     21 from matplotlib.backends.qt_compat import QtGui
     22 

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/formlayout.py in <module>()
     54 
     55 from matplotlib import colors as mcolors
---> 56 from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
     57 
     58 

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_compat.py in <module>()
    135     # have been changed in the above if block
    136     if QT_API in [QT_API_PYQT, QT_API_PYQTv2]:  # PyQt4 API
--> 137         from PyQt4 import QtCore, QtGui
    138 
    139         try:

ModuleNotFoundError: No module named 'PyQt4'

Trying to pin PyQt to 4.11 doesn't work because it breaks other dependencies. Any solution?

@ccordoba12
Copy link

You need to run

%matplotlib qt5

now, instead of

%matplotlib qt

@nihalf
Copy link
Author

nihalf commented Feb 16, 2017

Still doesnt fix it. I've checked the matplolibrc file, and the backend specified is Qt5Agg. I still get the "no module named PyQt4" error

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-5-061ce91f2477> in <module>()
      1 df['Adj Close'].plot()
----> 2 get_ipython().magic('matplotlib qt5')
      3 plt.show()

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
   2156         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2157         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158         return self.run_line_magic(magic_name, magic_arg_s)
   2159 
   2160     #-------------------------------------------------------------------------

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
   2077                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2078             with self.builtin_trap:
-> 2079                 result = fn(*args,**kwargs)
   2080             return result
   2081 

<decorator-gen-104> in matplotlib(self, line)

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/magics/pylab.py in matplotlib(self, line)
     98             print("Available matplotlib backends: %s" % backends_list)
     99         else:
--> 100             gui, backend = self.shell.enable_matplotlib(args.gui)
    101             self._show_matplotlib_backend(args.gui, backend)
    102 

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   2945                 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
   2946 
-> 2947         pt.activate_matplotlib(backend)
   2948         pt.configure_inline_support(self, backend)
   2949 

/home/nihalf/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py in activate_matplotlib(backend)
    293 
    294     import matplotlib.pyplot
--> 295     matplotlib.pyplot.switch_backend(backend)
    296 
    297     # This must be imported last in the matplotlib series, after

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in switch_backend(newbackend)
    231     matplotlib.use(newbackend, warn=False, force=True)
    232     from matplotlib.backends import pylab_setup
--> 233     _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
    234 
    235 

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/__init__.py in pylab_setup()
     30     # imports. 0 means only perform absolute imports.
     31     backend_mod = __import__(backend_name,
---> 32                              globals(),locals(),[backend_name],0)
     33 
     34     # Things we pull in from all backends

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py in <module>()
     14 
     15 from .backend_agg import FigureCanvasAgg
---> 16 from .backend_qt5 import QtCore
     17 from .backend_qt5 import QtGui
     18 from .backend_qt5 import FigureManagerQT

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py in <module>()
     24 
     25 from matplotlib.widgets import SubplotTool
---> 26 import matplotlib.backends.qt_editor.figureoptions as figureoptions
     27 
     28 from .qt_compat import (QtCore, QtGui, QtWidgets, _getSaveFileName,

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py in <module>()
     18 import matplotlib
     19 from matplotlib import cm, markers, colors as mcolors
---> 20 import matplotlib.backends.qt_editor.formlayout as formlayout
     21 from matplotlib.backends.qt_compat import QtGui
     22 

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/formlayout.py in <module>()
     54 
     55 from matplotlib import colors as mcolors
---> 56 from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
     57 
     58 

/home/nihalf/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_compat.py in <module>()
    135     # have been changed in the above if block
    136     if QT_API in [QT_API_PYQT, QT_API_PYQTv2]:  # PyQt4 API
--> 137         from PyQt4 import QtCore, QtGui
    138 
    139         try:

ModuleNotFoundError: No module named 'PyQt4'

@ccordoba12 ccordoba12 reopened this Feb 16, 2017
@mationai
Copy link

mationai commented Feb 22, 2017

Tried suggested

%matplotlib qt5

Errored, see below.

Ok, let's try to install pyqt4, nope, errored:

conda install pyqt=4
Fetching package metadata .........
Solving package specifications: .


UnsatisfiableError: The following specifications were found to be in conflict:
  - pyqt 4* -> python 2.6* -> openssl 1.0.1*
  - python 3.6*
Use "conda info <package>" to see the dependencies for each package.

Info:

conda --version
conda 4.3.13

python --version
Python 3.6.0 :: Continuum Analytics, Inc.

conda list pyqt
pyqt                      5.6.0                    py36_2  

Please help, thank you.

Error:

Warning: Cannot change to a different GUI toolkit: qt5. Using qt instead.
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-98ea7e3b93bd> in <module>()
      3 import glob
      4 import matplotlib.pyplot as plt
----> 5 get_ipython().magic('matplotlib qt5')
      6 
      7 

/Users/john/miniconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
   2156         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2157         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158         return self.run_line_magic(magic_name, magic_arg_s)
   2159 
   2160     #-------------------------------------------------------------------------

/Users/john/miniconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
   2077                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2078             with self.builtin_trap:
-> 2079                 result = fn(*args,**kwargs)
   2080             return result
   2081 

<decorator-gen-104> in matplotlib(self, line)

/Users/john/miniconda3/lib/python3.6/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

/Users/john/miniconda3/lib/python3.6/site-packages/IPython/core/magics/pylab.py in matplotlib(self, line)
     98             print("Available matplotlib backends: %s" % backends_list)
     99         else:
--> 100             gui, backend = self.shell.enable_matplotlib(args.gui)
    101             self._show_matplotlib_backend(args.gui, backend)
    102 

/Users/john/miniconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   2947                 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
   2948 
-> 2949         pt.activate_matplotlib(backend)
   2950         pt.configure_inline_support(self, backend)
   2951 

/Users/john/miniconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py in activate_matplotlib(backend)
    306 
    307     import matplotlib.pyplot
--> 308     matplotlib.pyplot.switch_backend(backend)
    309 
    310     # This must be imported last in the matplotlib series, after

/Users/john/miniconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in switch_backend(newbackend)
    231     matplotlib.use(newbackend, warn=False, force=True)
    232     from matplotlib.backends import pylab_setup
--> 233     _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
    234 
    235 

/Users/john/miniconda3/lib/python3.6/site-packages/matplotlib/backends/__init__.py in pylab_setup()
     30     # imports. 0 means only perform absolute imports.
     31     backend_mod = __import__(backend_name,
---> 32                              globals(),locals(),[backend_name],0)
     33 
     34     # Things we pull in from all backends

/Users/john/miniconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt4agg.py in <module>()
     16 
     17 
---> 18 from .backend_qt5agg import FigureCanvasQTAggBase as _FigureCanvasQTAggBase
     19 
     20 from .backend_agg import FigureCanvasAgg

/Users/john/miniconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py in <module>()
     14 
     15 from .backend_agg import FigureCanvasAgg
---> 16 from .backend_qt5 import QtCore
     17 from .backend_qt5 import QtGui
     18 from .backend_qt5 import FigureManagerQT

/Users/john/miniconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py in <module>()
     24 
     25 from matplotlib.widgets import SubplotTool
---> 26 import matplotlib.backends.qt_editor.figureoptions as figureoptions
     27 
     28 from .qt_compat import (QtCore, QtGui, QtWidgets, _getSaveFileName,

/Users/john/miniconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py in <module>()
     18 import matplotlib
     19 from matplotlib import cm, markers, colors as mcolors
---> 20 import matplotlib.backends.qt_editor.formlayout as formlayout
     21 from matplotlib.backends.qt_compat import QtGui
     22 

/Users/john/miniconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/formlayout.py in <module>()
     54 
     55 from matplotlib import colors as mcolors
---> 56 from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
     57 
     58 

/Users/john/miniconda3/lib/python3.6/site-packages/matplotlib/backends/qt_compat.py in <module>()
    135     # have been changed in the above if block
    136     if QT_API in [QT_API_PYQT, QT_API_PYQTv2]:  # PyQt4 API
--> 137         from PyQt4 import QtCore, QtGui
    138 
    139         try:

ModuleNotFoundError: No module named 'PyQt4'

@mationai
Copy link

Retried with python 3.5.2 env, exactly the same

ModuleNotFoundError: No module named 'PyQt4'

error.

@nihalf
Copy link
Author

nihalf commented Feb 22, 2017

For anybody else with this error when using Jupyter notebooks, a workaround is to specify the "nbagg" backend when importing matplotlib. It isn't great if you want to use Qt5, but it will do in a pinch.

@mationai
Copy link

Ok,

conda install qt=4

in python 3.5.2 env made the error go away. Have not tried this in 3.6.0 env yet.

But error still exists with the default qt and pyqt of 5.x

@mingwandroid
Copy link

mingwandroid commented Feb 22, 2017

This works completely fine for me on macOS. Here is the procedure I followed, from start to finish. @nihalf, @fuzzthink, please try it and post your results:

pushd /tmp
curl -SLO https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
bash ./Miniconda3-latest-MacOSX-x86_64.sh -b -p /tmp/mpl
source /tmp/mpl/bin/activate
conda install jupyter ipython matplotlib -y
jupyter notebook

In a new Python 3 notebook:

get_ipython().magic('matplotlib qt5')
import matplotlib.pyplot as plt
plt.plot([1,2,3,4],[1,1.6,4.5, 2])

screen shot 2017-02-22 at 12 58 56

Finally, to cleanup:

rm -rf /tmp/mpl

@mingwandroid
Copy link

Please can you give the requested feedback on this issue?

@ccordoba12
Copy link

@mingwandroid, I think we could merge this one with issue #1068.

@JunHuang023
Copy link

@mingwandroid, Hi, you suggestion worked for me, I was not sure about what I have done, though.
I noticed that
(root) somename-MacBook-Pro:myname$ ,
previously it was like:
somename-MacBook-Pro:myname$ ,
Does this means I am running my mac as "root", do I need to go back the "routine" as a a "user"?
if so, what do I needs to do?
Thanks!

@mingwandroid
Copy link

mingwandroid commented May 8, 2017

I was not sure about what I have done, though.

All we have done here is to create a brand new temporary installation of Miniconda to show that, under such a clean/fresh install, matplotlib with the qt backend works fine. This means that any problems you are having with your other installation are not system-wide issues (i.e. they are isolated to that installation).

Does this means I am running my mac as "root"

No it doesn't. (root) here is referring to the root conda environment and has nothing to do with your user (which is by the look of it, myname).

@Gerenuk
Copy link

Gerenuk commented Jun 11, 2017

I've just had similar issues. ipython profile create fixed it for me, which creates the two (default) config files.

@mingwandroid
Copy link

Closing due to lack of requested feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants