pickle and py2exe

J

Justin Straube

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
 
C

Catfish

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

Johan Lindberg

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
 
J

Justin Straube

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
 
J

Justin Straube

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
 
J

Johan Lindberg

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
 
D

Daniel Bickett

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
 
J

Justin Straube

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Py2exe 0
pickle error: can't pickle instancemethod objects 2
__getattr__, __setattr__ and pickle 6
Best way to pickle functions 7
freeze utility and pickle 1
py2exe problem 1
pickle problem 10
py2exe error 1

Members online

Forum statistics

Threads
473,770
Messages
2,569,585
Members
45,080
Latest member
mikkipirss

Latest Threads

Top