jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.62k stars 4.88k forks source link

%matplotlib attempts to activate OS-specific backend #3684

Open dbrnz opened 6 years ago

dbrnz commented 6 years ago

%matplotlib tries to activate the system specific backend (from matplotlib.rcParamsOrig['backend'] and then remembers this. A subsequent %matplotlib notebook fails with "Warning: Cannot change to a different GUI toolkit: notebook."

This is with Python 3.6.4 and notebook 5.4.1 under macOS.

%matplotlib
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)

<ipython-input-1-a49a4afc47c5> in <module>()
----> 1 get_ipython().run_line_magic('matplotlib', '')

~/.pyenv/versions/3.6.4/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2093                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2094             with self.builtin_trap:
-> 2095                 result = fn(*args,**kwargs)
   2096             return result
   2097 

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

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

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

~/.pyenv/versions/3.6.4/lib/python3.6/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   2976                 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
   2977 
-> 2978         pt.activate_matplotlib(backend)
   2979         pt.configure_inline_support(self, backend)
   2980 

~/.pyenv/versions/3.6.4/lib/python3.6/site-packages/IPython/core/pylabtools.py in activate_matplotlib(backend)
    305     matplotlib.rcParams['backend'] = backend
    306 
--> 307     import matplotlib.pyplot
    308     matplotlib.pyplot.switch_backend(backend)
    309 

~/.pyenv/versions/3.6.4/lib/python3.6/site-packages/matplotlib/pyplot.py in <module>()
    113 ## Global ##
    114 
--> 115 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
    116 
    117 _IP_REGISTERED = None

~/.pyenv/versions/3.6.4/lib/python3.6/site-packages/matplotlib/backends/__init__.py in pylab_setup(name)
     60     # imports. 0 means only perform absolute imports.
     61     backend_mod = __import__(backend_name, globals(), locals(),
---> 62                              [backend_name], 0)
     63 
     64     # Things we pull in from all backends

~/.pyenv/versions/3.6.4/lib/python3.6/site-packages/matplotlib/backends/backend_macosx.py in <module>()
     15 
     16 import matplotlib
---> 17 from matplotlib.backends import _macosx
     18 
     19 from .backend_agg import FigureCanvasAgg

RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
%matplotlib notebook
Warning: Cannot change to a different GUI toolkit: notebook. Using osx instead.
minrk commented 6 years ago

%matplotlib without any arguments selects the default backend, so it will depend on matplotlib configuration.

What's pip list? I thought the latest ipykernel and/or matplotlib made inline the default backend.

dbrnz commented 6 years ago

Here is pip list.

Package                  Version          
------------------------ -----------------
alabaster                0.7.10           
appnope                  0.1.0            
arrow                    0.12.1           
Babel                    2.5.3            
binaryornot              0.4.4            
bleach                   2.1.3            
certifi                  2018.1.18        
chardet                  3.0.4            
click                    6.7              
cookiecutter             1.6.0            
cssselect2               0.2.1            
cycler                   0.10.0           
decorator                4.2.1            
dionysus                 2.0.4            
docutils                 0.14             
dukpy                    0.1.0            
entrypoints              0.2.3            
future                   0.16.0           
html5lib                 1.0.1            
idna                     2.6              
imagesize                1.0.0            
inspyred                 1.0.1            
ipykernel                4.8.2            
ipython                  6.2.1            
ipython-genutils         0.2.0            
ipyvolume                0.4.5            
ipywebrtc                0.3.0            
ipywidgets               7.1.2            
javascripthon            0.8              
jedi                     0.11.1           
Jinja2                   2.10             
jinja2-time              0.2.0            
jsonschema               2.6.0            
jupyter                  1.0.0            
jupyter-client           5.2.3            
jupyter-console          5.2.0            
jupyter-core             4.4.0            
jupyterlab               0.31.12          
jupyterlab-launcher      0.10.5           
kiwisolver               1.0.1            
lxml                     4.1.1            
macropy3                 1.0.4.dev2       
MarkupSafe               1.0              
matplotlib               2.2.2            
mistune                  0.8.3            
mpmath                   1.0.0            
mypy                     0.570            
Naked                    0.1.31           
nbconvert                5.3.1            
nbformat                 4.4.0            
networkx                 2.1              
notebook                 5.4.1            
numpy                    1.14.2           
packaging                17.1             
pandas                   0.22.0           
pandocfilters            1.4.2            
parso                    0.1.1            
pdfrw                    0.4              
pexpect                  4.4.0            
pickleshare              0.7.4            
Pillow                   5.0.0            
pip                      10.0.1           
Platypus                 1.0              
Platypus-Opt             1.0.2            
ply                      3.11             
poyo                     0.4.1            
prompt-toolkit           1.0.15           
ptyprocess               0.5.2            
pudb                     2017.1.4         
PyExecJS                 1.5.1            
Pygments                 2.2.0            
pyparsing                2.2.0            
PyQt5                    5.10.1           
python-dateutil          2.7.2            
pythreejs                0.4.1            
pytz                     2018.3           
PyYAML                   3.12             
pyzmq                    17.0.0           
qtconsole                4.3.1            
reportlab                3.4.0            
requests                 2.18.4           
rst2pdf                  0.93.dev-r0      
scipy                    1.0.1            
Send2Trash               1.5.0            
setuptools               39.0.1           
Shapely                  1.6.4.post1      
simplegeneric            0.8.1            
sip                      4.19.8           
six                      1.11.0           
snowballstemmer          1.2.1            
Sphinx                   1.7.2.dev20180411
sphinxcontrib-websupport 1.0.1            
sympy                    1.1.1            
terminado                0.8.1            
testpath                 0.3.1            
tinycss2                 0.6.1            
tornado                  5.0.1            
traitlets                4.3.2            
traittypes               0.0.6            
Transcrypt               3.6.101          
typed-ast                1.1.0            
urllib3                  1.22             
urwid                    2.0.1            
vispy                    0.5.2            
wcwidth                  0.1.7            
webencodings             0.5.1            
whichcraft               0.4.1            
widgetsnbextension       3.1.4            
winpdb                   1.3.6