Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pickle and py2exe

6 views
Skip to first unread message

Justin Straube

unread,
Nov 30, 2004, 11:23:24 PM11/30/04
to
Hello,

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

Catfish

unread,
Nov 30, 2004, 11:48:39 PM11/30/04
to
I did this a while back, and I can't remember exactly. Therefore, I may only
be able to give you a push in the right direction until someone else can
answer it fully.

However, I think you have to force the db into the py2exe compile. I think
it's something like this:

--force-imports dbhash

Try this and see if it works.


"Justin Straube" <justin...@charter.net> wrote in message
news:qphqq0poq7d842fvm...@4ax.com...

Johan Lindberg

unread,
Dec 1, 2004, 2:45:59 PM12/1/04
to

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

Justin Straube

unread,
Dec 2, 2004, 6:48:00 PM12/2/04
to
On 1 Dec 2004 11:45:59 -0800, jo...@pulp.se (Johan Lindberg) wrote:


>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.

Thanks,

Justin

Johan Lindberg

unread,
Dec 3, 2004, 4:46:38 AM12/3/04
to
>>> 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:
self.append(rep.decode("string-escape"))
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
setup.py?
(don't forget to change windows= ["spam.py"] to console= ["spam.py"])

Also you might want to try the py2exe-users list (see
http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/py2exe-users).

BR
/Johan Lindberg

Justin Straube

unread,
Dec 2, 2004, 6:47:59 PM12/2/04
to
On Tue, 30 Nov 2004 22:48:39 -0600, "Catfish" <losnations@comca> wrote:

>I did this a while back, and I can't remember exactly. Therefore, I may only
>be able to give you a push in the right direction until someone else can
>answer it fully.
>
>However, I think you have to force the db into the py2exe compile. I think
>it's something like this:
>
>--force-imports dbhash
>
>Try this and see if it works.

Thanks Catfish,

This brought up an error, option: --force-import not recognized.

While looking into this, I had seen some mention of protocol option in pickle. I
hadnt specified anything for protocol, so it defaults to 0 though I dont know
what that is. Its my first time using pickle and second with py2exe.

Thanks for the suggestion, Ill keep trying at this and another idea without
pickle.

Justin

>"Justin Straube" <justinstraube@ch> wrote in message

Daniel Bickett

unread,
Dec 3, 2004, 8:25:32 AM12/3/04
to Justin Straube, pytho...@python.org
> While looking into this, I had seen some mention of protocol option in pickle. I
> hadnt specified anything for protocol, so it defaults to 0 though I dont know
> what that is. Its my first time using pickle and second with py2exe.

If you think this might be your problem, then it would be best to
specify your protocol using the variable HIGHEST_PROTOCOL as defined
in the Pickle module. However, if this does fix your problem, keep in
mind it won't fix the problem for earlier pickle versions.

Bickett

Justin Straube

unread,
Dec 5, 2004, 9:15:27 PM12/5/04
to
On 3 Dec 2004 01:46:38 -0800, johan@ (Johan Lindberg) wrote:

Thanks Johan,

>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 had found a stupid mistake in my setup.py. I corrected it and the .zip now has
the string_escape.pyc file in the correct path. And also the program runs as it
should.

> # 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
>setup.py?
>(don't forget to change windows= ["spam.py"] to console= ["spam.py"])

This gives a LookupError: no codec search function registered: can't find
encoding

I then tried with the encoding package added and the .exe did print the spam
string.

>Also you might want to try the py2exe-users list (see
>http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/py2exe-users).

Thanks, Ill check this out.


Regards,
Justin Straube

0 new messages