Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > weird pickle behavior in Python 3.1.2 + Eclipse 3.5.2

Reply
Thread Tools

weird pickle behavior in Python 3.1.2 + Eclipse 3.5.2

 
 
kirby.urner@gmail.com
Guest
Posts: n/a
 
      06-04-2010
Here we are in an Eclipse pydev console, running Python 3.1.2. For
the most part, everything is working great.

However...

>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))

C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC
v.1500 32 bit (Intel)]

>>> import pickle
>>> class Example:

.... def __init__(self):
.... self.name = "Hello"
.... def __repr__(self):
.... return "an Example object named {}".format(self.name)
....
....
>>> obj = Example()
>>> obj

an Example object named Hello

Note that I'm opening in binary, like I'm supposed to with this
latest protocol:

>>> f = open("testpickle.pkl",'wb')


Should be able to do this, no problemo:

>>> pickle.dump(obj, f)

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python31\lib\pickle.py", line 1354, in dump
Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle <class 'Example'>: attribute
lookup builtins.Example failed

The above works fine in "naked Python" 3.1.2 by the way.
So this could be a problem with Eclipse / Pydev and/or
user error. What am I missing?

Just normal data structures work:

>>> test = [1,2,3]
>>> pickle.dump(test,f)
>>> f.close()
>>>


Any other Eclipse users out there who can at least duplicate this
weirdness?

Kirby Urner
in Portland "Keep Portland Weird" Oregon

 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      06-04-2010
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Here we are in an Eclipse pydev console, running Python 3.1.2. For
> the most part, everything is working great.
>
> However...
>
>>>> import sys; print('%s %s' % (sys.executable or sys.platform,
>>>> sys.version))

> C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC
> v.1500 32 bit (Intel)]
>
>>>> import pickle
>>>> class Example:

> ... def __init__(self):
> ... self.name = "Hello"
> ... def __repr__(self):
> ... return "an Example object named {}".format(self.name)
> ...
> ...
>>>> obj = Example()
>>>> obj

> an Example object named Hello
>
> Note that I'm opening in binary, like I'm supposed to with this
> latest protocol:
>
>>>> f = open("testpickle.pkl",'wb')

>
> Should be able to do this, no problemo:
>
>>>> pickle.dump(obj, f)

> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "C:\Python31\lib\pickle.py", line 1354, in dump
> Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
> _pickle.PicklingError: Can't pickle <class 'Example'>: attribute
> lookup builtins.Example failed
>
> The above works fine in "naked Python" 3.1.2 by the way.
> So this could be a problem with Eclipse / Pydev and/or
> user error. What am I missing?
>
> Just normal data structures work:
>
>>>> test = [1,2,3]
>>>> pickle.dump(test,f)
>>>> f.close()
>>>>

>
> Any other Eclipse users out there who can at least duplicate this
> weirdness?


I can provoke the error in "naked" Python 3 by changing the
Example.__module__ attribute:

Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> class Example:

.... pass
....
>>> pickle.dumps(Example())

b'\x80\x03c__main__\nExample\nq\x00)\x81q\x01}q\x0 2b.'
>>> Example.__module__ = "builtins"
>>> pickle.dumps(Example())

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.1/pickle.py", line 1358, in dumps
Pickler(f, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle <class 'Example'>: attribute lookup
builtins.Example failed

What's the value of __module__ when you run your code in Eclipse?

Peter
 
Reply With Quote
 
 
 
 
kirby.urner@gmail.com
Guest
Posts: n/a
 
      06-04-2010
On Jun 4, 9:47*am, Peter Otten <(E-Mail Removed)> wrote:

> I can provoke the error in "naked" Python 3 by changing the
> Example.__module__ attribute:
>
> Python 3.1.1+ (r311:74480, Nov *2 2009, 15:45:00)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.


> >>> import pickle
> >>> class Example:

>
> ... * * pass
> ...
> >>> pickle.dumps(Example())

>
> b'\x80\x03c__main__\nExample\nq\x00)\x81q\x01}q\x0 2b.'


> >>> Example.__module__ = "builtins"
> >>> pickle.dumps(Example())

>
> Traceback (most recent call last):
> * File "<stdin>", line 1, in <module>
> * File "/usr/lib/python3.1/pickle.py", line 1358, in dumps
> * * Pickler(f, protocol, fix_imports=fix_imports).dump(obj)
> _pickle.PicklingError: Can't pickle <class 'Example'>: attribute lookup
> builtins.Example failed
>
> What's the value of __module__ when you run your code in Eclipse?
>
> Peter


Thank you for replying.

Here's from Eclipse console:

>>> Example.__module__

'builtins'

>>> __name__

'builtins'

Duplicating your result in naked Python:

Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> class Example:

pass

>>> import pickle
>>> Example.__module__

'__main__'
>>> f = open('testpickle.pkl','wb')
>>> obj = Example()
>>> obj

<__main__.Example object at 0x02A26690>
>>> pickle.dump(obj, f)


>>> Example.__module__ = 'builtins'
>>> obj2 = Example()


>>> pickle.dump(obj2, f)

Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
pickle.dump(obj2, f)
File "C:\Python31\lib\pickle.py", line 1354, in dump
Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle <class 'Example'>: attribute
lookup builtins.Example failed

So what if I'm in an Eclipse pydev console and
change the Example.__module__ to '__main__'....

>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))

C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC
v.1500 32 bit (Intel)]
>>> import pickle
>>> class Example:

.... pass
....
>>> Example.__module__

'builtins'
>>> Example.__module__ = '__main__'
>>> obj = Example()
>>> obj

<__main__.Example object at 0x029E8FD0>
>>> f = open('testpickle.pkl','wb')
>>> pickle.dump(obj, f)

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python31\lib\pickle.py", line 1354, in dump
Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle <class '__main__.Example'>:
attribute lookup __main__.Example failed
>>>


Dang.

Any insights?

Kirby
 
Reply With Quote
 
Peter Otten
Guest
Posts: n/a
 
      06-07-2010
(E-Mail Removed) wrote:

> On Jun 4, 9:47 am, Peter Otten <(E-Mail Removed)> wrote:
>
>> I can provoke the error in "naked" Python 3 by changing the
>> Example.__module__ attribute:
>>
>> Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00)
>> [GCC 4.4.1] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.

>
>> >>> import pickle
>> >>> class Example:

>>
>> ... pass
>> ...
>> >>> pickle.dumps(Example())

>>
>> b'\x80\x03c__main__\nExample\nq\x00)\x81q\x01}q\x0 2b.'

>
>> >>> Example.__module__ = "builtins"
>> >>> pickle.dumps(Example())

>>
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> File "/usr/lib/python3.1/pickle.py", line 1358, in dumps
>> Pickler(f, protocol, fix_imports=fix_imports).dump(obj)
>> _pickle.PicklingError: Can't pickle <class 'Example'>: attribute lookup
>> builtins.Example failed
>>
>> What's the value of __module__ when you run your code in Eclipse?
>>
>> Peter

>
> Thank you for replying.
>
> Here's from Eclipse console:
>
>>>> Example.__module__

> 'builtins'
>
>>>> __name__

> 'builtins'
>
> Duplicating your result in naked Python:
>
> Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit
> (Intel)] on win32
> Type "copyright", "credits" or "license()" for more information.
>>>> class Example:

> pass
>
>>>> import pickle
>>>> Example.__module__

> '__main__'
>>>> f = open('testpickle.pkl','wb')
>>>> obj = Example()
>>>> obj

> <__main__.Example object at 0x02A26690>
>>>> pickle.dump(obj, f)

>
>>>> Example.__module__ = 'builtins'
>>>> obj2 = Example()

>
>>>> pickle.dump(obj2, f)

> Traceback (most recent call last):
> File "<pyshell#12>", line 1, in <module>
> pickle.dump(obj2, f)
> File "C:\Python31\lib\pickle.py", line 1354, in dump
> Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
> _pickle.PicklingError: Can't pickle <class 'Example'>: attribute
> lookup builtins.Example failed
>
> So what if I'm in an Eclipse pydev console and
> change the Example.__module__ to '__main__'....
>
>>>> import sys; print('%s %s' % (sys.executable or sys.platform,
>>>> sys.version))

> C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC
> v.1500 32 bit (Intel)]
>>>> import pickle
>>>> class Example:

> ... pass
> ...
>>>> Example.__module__

> 'builtins'
>>>> Example.__module__ = '__main__'
>>>> obj = Example()
>>>> obj

> <__main__.Example object at 0x029E8FD0>
>>>> f = open('testpickle.pkl','wb')
>>>> pickle.dump(obj, f)

> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "C:\Python31\lib\pickle.py", line 1354, in dump
> Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
> _pickle.PicklingError: Can't pickle <class '__main__.Example'>:
> attribute lookup __main__.Example failed
>>>>

>
> Dang.
>
> Any insights?


Sorry, no. Consider a bug report to the pydev project.

Peter
 
Reply With Quote
 
Fabio Zadrozny
Guest
Posts: n/a
 
      06-08-2010
On Mon, Jun 7, 2010 at 6:30 AM, Peter Otten <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
>
>> On Jun 4, 9:47 am, Peter Otten <(E-Mail Removed)> wrote:
>>
>>> I can provoke the error in "naked" Python 3 by changing the
>>> Example.__module__ attribute:
>>>
>>> Python 3.1.1+ (r311:74480, Nov *2 2009, 15:45:00)
>>> [GCC 4.4.1] on linux2
>>> Type "help", "copyright", "credits" or "license" for more information.

>>
>>> >>> import pickle
>>> >>> class Example:
>>>
>>> ... * * pass
>>> ...
>>> >>> pickle.dumps(Example())
>>>
>>> b'\x80\x03c__main__\nExample\nq\x00)\x81q\x01}q\x0 2b.'

>>
>>> >>> Example.__module__ = "builtins"
>>> >>> pickle.dumps(Example())
>>>
>>> Traceback (most recent call last):
>>> File "<stdin>", line 1, in <module>
>>> File "/usr/lib/python3.1/pickle.py", line 1358, in dumps
>>> Pickler(f, protocol, fix_imports=fix_imports).dump(obj)
>>> _pickle.PicklingError: Can't pickle <class 'Example'>: attribute lookup
>>> builtins.Example failed
>>>
>>> What's the value of __module__ when you run your code in Eclipse?
>>>
>>> Peter

>>
>> Thank you for replying.
>>
>> Here's from Eclipse console:
>>
>>>>> Example.__module__

>> 'builtins'
>>
>>>>> __name__

>> 'builtins'
>>
>> Duplicating your result in naked Python:
>>
>> Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit
>> (Intel)] on win32
>> Type "copyright", "credits" or "license()" for more information.
>>>>> class Example:

>> pass
>>
>>>>> import pickle
>>>>> Example.__module__

>> '__main__'
>>>>> f = open('testpickle.pkl','wb')
>>>>> obj = Example()
>>>>> obj

>> <__main__.Example object at 0x02A26690>
>>>>> pickle.dump(obj, f)

>>
>>>>> Example.__module__ = 'builtins'
>>>>> obj2 = Example()

>>
>>>>> pickle.dump(obj2, f)

>> Traceback (most recent call last):
>> * File "<pyshell#12>", line 1, in <module>
>> * * pickle.dump(obj2, f)
>> * File "C:\Python31\lib\pickle.py", line 1354, in dump
>> * * Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
>> _pickle.PicklingError: Can't pickle <class 'Example'>: attribute
>> lookup builtins.Example failed
>>
>> So what if I'm in an Eclipse pydev console and
>> change the Example.__module__ to '__main__'....
>>
>>>>> import sys; print('%s %s' % (sys.executable or sys.platform,
>>>>> sys.version))

>> C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC
>> v.1500 32 bit (Intel)]
>>>>> import pickle
>>>>> class Example:

>> ... * * pass
>> ...
>>>>> Example.__module__

>> 'builtins'
>>>>> Example.__module__ = '__main__'
>>>>> obj = Example()
>>>>> obj

>> <__main__.Example object at 0x029E8FD0>
>>>>> f = open('testpickle.pkl','wb')
>>>>> pickle.dump(obj, f)

>> Traceback (most recent call last):
>> * File "<console>", line 1, in <module>
>> * File "C:\Python31\lib\pickle.py", line 1354, in dump
>> * * Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
>> _pickle.PicklingError: Can't pickle <class '__main__.Example'>:
>> attribute lookup __main__.Example failed
>>>>>

>>
>> Dang.
>>
>> Any insights?

>
> Sorry, no. Consider a bug report to the pydev project.
>



I've taken a look at the pydev code and the issue seems to be in
python itself. See: http://bugs.python.org/issue8943

Cheers,

Fabio
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: A Weird Appearance for a Weird Site dorayme HTML 1 01-21-2011 06:51 AM
Re: A Weird Appearance for a Weird Site richard HTML 0 01-21-2011 06:46 AM
Weird Python startup behavior between different drives on PowerPCplatform jwahlmann@gmail.com Python 1 07-21-2008 03:51 PM
pickle error: can't pickle instancemethod objects Michele Simionato Python 2 05-23-2008 08:29 AM
a pickle's pickle temposs@gmail.com Python 4 08-02-2005 07:20 PM



Advertisments