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

tornado now a requirement? #5615

Closed
jankatins opened this issue Dec 4, 2015 · 3 comments
Closed

tornado now a requirement? #5615

jankatins opened this issue Dec 4, 2015 · 3 comments

Comments

@jankatins
Copy link
Contributor

If I explicitly use a different backend, IMO the nbagg backend shouldn't be loaded.

C:\portabel\miniconda\envs\katins2\lib\site-packages\matplotlib\__init__.py:1355: UserWarning:  This call to matplotlib.use() has no effect
because the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

  warnings.warn(_use_error_msg)
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-1fdbaaa8856e> in <module>()
      2 import matplotlib as mpl
      3 mpl.use('Agg')
----> 4 import matplotlib.pyplot as plt
      5 import matplotlib.animation as animation
      6 def updatefig(i):

C:\portabel\miniconda\envs\katins2\lib\site-packages\matplotlib\pyplot.py in <module>()
    112 
    113 from matplotlib.backends import pylab_setup
--> 114 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
    115 
    116 _IP_REGISTERED = None

C:\portabel\miniconda\envs\katins2\lib\site-packages\matplotlib\backends\__init__.pyc 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

C:\portabel\miniconda\envs\katins2\lib\site-packages\matplotlib\backends\backend_nbagg.py in <module>()
     12 from uuid import uuid4 as uuid
     13 
---> 14 import tornado.ioloop
     15 
     16 from IPython.display import display, Javascript, HTML

ImportError: No module named tornado.ioloop
@tacaswell
Copy link
Member

It looks like matplotlib.backends is getting imported by something before you can call use so it is having no effect. Can you try passing force=True into use.

@jankatins
Copy link
Contributor Author

Ok, I tried to reproduce it and I couldn't: If I set agg, it loads the agg backend and not nbagg:

from sys import modules
import matplotlib
matplotlib.use('Agg')
middle = sorted([x for x in modules.keys() if x.startswith("matplotlib.bac")])
import matplotlib.pylab as plt
last = sorted([x for x in modules.keys() if x.startswith("matplotlib.bac")])

diff = set(last) - set(middle)
print(middle) # empty
print(diff) # only the agg backends

-> closing and sorry for the noise...

@jankatins
Copy link
Contributor Author

Ok I think I got it:

first cell included a :

%matplotlib notebook

-> I got an error about tornado, removed the line and then executed the cell with the mpl.use("agg"). -> it cached the backend name from the matplotlib notebook call to mpl.use() and now you can't reset it.

Not sure if there is a case for "if the backend init/loading didn't work, remove the cached backend name from use(...)? Or let use() overwrite if the backend isn't in fact initialized? Similar to this:

import matplotlib
matplotlib.use('nbAgg')
matplotlib.use('Agg')
import matplotlib.pyplot # works because backend is now agg
import matplotlib
matplotlib.use('nbAgg')
try:
    import matplotlib.pyplot
except ImportError:
    matplotlib.use('Agg') # gives a warning but no backend is yet loaded... 
    import matplotlib.pyplot # does not work...

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

No branches or pull requests

2 participants