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

dump_session in %pylab mode #78

Closed
nikohansen opened this issue Jan 26, 2015 · 5 comments
Closed

dump_session in %pylab mode #78

nikohansen opened this issue Jan 26, 2015 · 5 comments

Comments

@nikohansen
Copy link

In IPython:

import dill
dill.dump_session('test.pkl')
%pylab
dill.dump_session('test.pkl')

The second dump fails with PicklingError: Can't pickle <class 'matplotlib.axes._subplots.AxesSubplot'>: it's not found as matplotlib.axes._subplots.AxesSubplot

IPython 2.3.1 and Python 2.7.9 from Anaconda 2.1.0 (64bit) on OSX 10.9. I can post the entire trace if desired.

@nikohansen
Copy link
Author

%pylab does the following:

import numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot 
np = numpy
plt = pyplot

from IPython.core.pylabtools import figsize, getfigs

from pylab import *
from numpy import *

It turns out that the above problem comes from the pylab import *. Also from numpy import * leads to the pickle error Can't pickle <type 'numpy.int64'>: it's not the same object as numpy.int64. There is no problem without the last two from ... import * lines.

@mmckerns
Copy link
Member

This seems very much related to issue #4, which was closed as the matplotlib developers made a many of the difficult objects that pylab imports picklable.

The numpy.int64 sounds like an issue that would probably be best handled on this list as a new issue, with a possible include of the numpy devs. Pickling the objects coming from pylab are most likely to be handled by the matplotlib devs… however, it's quite possible that the response might be never import using from pylab import *. If that's the case, then it may be worthwhile to include the IPython devs in the discussion. I'm including @pelson, @fperez, and @charris here.

I can reproduce your errors for both, and neither are specific to %pylab in IPython. It's a failure of the * import in numpy and pylab. All of the objects just don't pickle as imported, so it's only an IPython concern in as much as they support a pylab mode.

I'm going to leave this ticket open as compatibility with IPython in pylab mode, and open a new ticket for the numpy.int64 (and more generally numpy import *). This ticket will continue for the from pylab import * part of the issue.

Would you mind reading #4? The next move may be to either submit a matplotlib ticket or an IPython ticket, depending on the response you get here. Sound good?

@mmckerns
Copy link
Member

The namespace magic going on here is most likely the issue...

pickle.PicklingError: Can't pickle <class 'matplotlib.axes._subplots.AxesSubplot'>: it's not found as matplotlib.axes._subplots.AxesSubplot

as it seems you can't directly import this class.

@nikohansen
Copy link
Author

Thanks for the answer, I hadn't see the previous issue (my search was apparently too superficial). I would vote one up for a dump_session(ignore=True) use case, in particular as this is a work around not only for this particular case. Otherwise it looks like just another reason to not import *. Thanks again.

@mmckerns
Copy link
Member

Looks like this works with #101.

Python 2.7.9 (default, Dec 11 2014, 01:21:43) 
Type "copyright", "credits" or "license" for more information.

IPython 3.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import dill

In [2]: %pylab
Using matplotlib backend: MacOSX
Populating the interactive namespace from numpy and matplotlib

In [3]: dill.dump_session(byref=True)

In [4]: 

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

2 participants