2 Feb 2011 04:50
Re: Cython + Pickle: Can't pickle <type ...> it's not found as ...
Carl Vondrick <cvondrick <at> gmail.com>
2011-02-02 03:50:19 GMT
2011-02-02 03:50:19 GMT
It appears I had something funny going on with setuptools/distutils/ distribute/easy_install/pip. Moreover, my version control shows no changes and it works now.On Feb 1, 5:55 pm, Robert Bradshaw <rober... <at> math.washington.edu> wrote: > On Tue, Feb 1, 2011 at 12:01 PM, Carl Vondrick <cvondr... <at> gmail.com> wrote: > > I'm trying to pickle one of my Cython classes. It's defined like: > > > cdef class Box(object): > > def __init__(self, a): > > self.a = a > > > def __reduce__(self): > > return (Box, (self.a,)) > > > But, when I pickle this object, I get the error: > > > a = Box(1) > > pickle.dump(a, open("foo", "w")) > > > I get the error: Can't pickle <type 'module.Box'>: it's not found as > > module.Box > > > For what it's worth, the Box class is defined in an external module > > installed via setuptools. > > > Any idea what's going on? As far as I can tell, the __reduce__ method > > isn't even being called. > > No idea, that works fine for me (well, inserting "cdef object a" into > Box's definition first). > > - Robert > > ------------------------------------------------------------------- > > import pickle > > cdef class Box(object): > cdef a > def __init__(self, a): > self.a = a > > def __reduce__(self): > return (Box, (self.a,)) > > def __repr__(self): > return "Box(%s)" % self.a > > a = Box(1) > print "a", a > s = pickle.dumps(a) > print "s", s > print pickle.loads(s)
On Feb 1, 5:55 pm, Robert Bradshaw <rober... <at> math.washington.edu>
wrote:
> On Tue, Feb 1, 2011 at 12:01 PM, Carl Vondrick <cvondr... <at> gmail.com> wrote:
> > I'm trying to pickle one of my Cython classes. It's defined like:
>
> > cdef class Box(object):
> > def __init__(self, a):
> > self.a = a
>
> > def __reduce__(self):
> > return (Box, (self.a,))
>
> > But, when I pickle this object, I get the error:
>
> > a = Box(1)
> > pickle.dump(a, open("foo", "w"))
>
> > I get the error: Can't pickle <type 'module.Box'>: it's not found as
> > module.Box
>
> > For what it's worth, the Box class is defined in an external module
> > installed via setuptools.
>
> > Any idea what's going on? As far as I can tell, the __reduce__ method
> > isn't even being called.
>
> No idea, that works fine for me (well, inserting "cdef object a" into
> Box's definition first).
>
> - Robert
>
> -------------------------------------------------------------------
>
> import pickle
>
> cdef class Box(object):
> cdef a
> def __init__(self, a):
> self.a = a
>
> def __reduce__(self):
> return (Box, (self.a,))
>
> def __repr__(self):
> return "Box(%s)" % self.a
>
> a = Box(1)
> print "a", a
> s = pickle.dumps(a)
> print "s", s
> print pickle.loads(s)
RSS Feed