pickle and py2exe

Johan Lindberg johan at pulp.se
Fri Dec 3 10:46:38 CET 2004

>>> Im trying to compile a script with py2exe. The pickle module is
causing the
>>> program to give an error.
>>> Traceback (most recent call last):
>>>   File "SETIstat.pyw", line 330, in ?
>>>   File "SETIstat.pyw", line 84, in start_up
>>>   File "SETIstat.pyw", line 79, in config_load
>>>   File "pickle.pyc", line 1390, in load
>>>   File "pickle.pyc", line 872, in load
>>>   File "pickle.pyc", line 985, in load_string
>>> LookupError: unknown encoding: string-escape
>>> the data in the pickled file is a dictionary containing a couple
>>> strings. The
>>> strings do contain \n and \t charaters but no other special
characters or
>>> anything. 
>>> Does anyone have any suggestions to what I can try to get around
this? The
>>> pickle module works fine when the .pyw file is run. Its only when
I compile
>>> this is there an issue. 
>>> Thanks for any help,
>>> Justin

>>Have you included string-escape encoding in your setup.py?
>>My guess is that you can fix the problem with something similar to:
>> from distutils.core import setup
>> import py2exe
>> opts = { "py2exe": { "packages": ["encodings"], } }
>> setup(windows= ["spam.py"], options= opts)
>>in your setup.py.
>>Hope it helps
>>/Johan Lindberg
> Thanks Johan,  but unfortunately the same traceback is given in the log. 
> I should have mentioned in my previous post that Im using win2000, if it
> matters any. 

Hi Justin.

I'm assuming that your library.zip now has several encoding-files in
it? And more specifically that you have a file called
"string_escape.pyc" in path "encodings". Right?

I don't think it's got anything to do with your windows version but it
might be helpful to know your python and py2exe versions.
Unfortunately I haven't been able to reproduce the error on either of
my windows machines (using python 2.3.4 and py2exe 0.5.3 on both, one
is win2k and the other XP).

Line 985 in pickle.py says:
so that's why you need the encoding, even though you "don't use it".
Will the same lookup error show up in a smallest possible program,
such as:

 # encoding= iso-8859-1
 spam= "Det här är svenska"
 print spam.decode("string-escape")

What happens when you compile that script to an exe using the above
(don't forget to change windows= ["spam.py"] to console= ["spam.py"])

Also you might want to try the py2exe-users list (see

/Johan Lindberg

More information about the Python-list mailing list