Greetings:

 

This is my first posting on this mailing list.  I have been using py2exe for about six months now, always on simple stuff.  This is my first problem with the package. 

 

I am writing a dice game (a variation on Yahtzee).  I am now adding persistent score history information.  I use a Python dictionary to store this data:  top ten scores, bottom ten scores, number of games played, etc.  I want to store this data in an .xml file between game sessions.  The scheme works fine in my working directory from a command prompt, but fails in the .exe file created by py2exe. 

 

Here is the relevant code from my module:

>>>>>>>>>> 

from xml.marshal.generic import Marshaller, Unmarshaller

class YahtBGCScores(object):

   

    def __init__(self):

        self.xmlm = Marshaller()

        self.xmlu = Unmarshaller()

        self.fname = "yahtBGC.xml"

        try:

            scorefile = open(self.fname,"r")

            self.scores = self.xmlu.load(scorefile)

            scorefile.close()

        except IOError:

            self.scores =   {

                'session':      {

                    'ngames': ['Number of games', 0],

                    'avg':    ['Average score',   0],

                    'high':   ['High score',      TopNList(1)],

                    'low':    ['Low score',       BottomNList(1)],

                },

                'resettable':   {

                    'ngames': ['Number of games', 0],

                    'avg':    ['Average score',   0],

                    'high':   ['Top ten',         TopNList(10)],

                    'low':    ['Bottom ten',      BottomNList(10)],

                },

                                      

                'permanent':    {

                    'ngames': ['Number of games', 0],

                    'avg':    ['Average score',   0],

                    'high':   ['Top ten',         TopNList(10)],

                    'low':    ['Bottom ten',      BottomNList(10)],

                },

            }

 

    def __del__(self):

        scorefile = open(self.fname,"w")

        self.xmlm.dump(self.scores, scorefile)

        scorefile.close()

>>>>>>>>>> 

 

Here is my (laughingly simple) setup module:

>>>>>>>>>> 

# setup.py

from distutils.core import setup

import py2exe

 

options = {

    "bundle_files": 1,

    "ascii": 1, # to make a smaller executable, don't include the encodings

    "compressed": 1, # compress the library archive

    }

 

setup(

    #options={"py2exe": options},

    #zipfile=None, # append zip-archive to the executable.

    console=["yahtBGC.py"]

    )

>>>>>>>>>> 

 

Here is the relevant output from py2exe, showing that the needed xml module is being found and included. 

>>>>>>>>>> 

creating J:\My Documents\My Projects\Python\yahtBGC\build\bdist.win32\winexe\col

lect-2.3\xml

byte-compiling C:\Python23\lib\site-packages\_xmlplus\marshal\__init__.py to xml

\marshal\__init__.pyc

creating J:\My Documents\My Projects\Python\yahtBGC\build\bdist.win32\winexe\col

lect-2.3\xml\marshal

byte-compiling C:\Python23\lib\site-packages\_xmlplus\marshal\generic.py to xml\

marshal\generic.pyc

byte-compiling C:\Python23\lib\site-packages\_xmlplus\sax\__init__.py to xml\sax

\__init__.pyc

creating J:\My Documents\My Projects\Python\yahtBGC\build\bdist.win32\winexe\col

lect-2.3\xml\sax

byte-compiling C:\Python23\lib\site-packages\_xmlplus\sax\_exceptions.py to xml\

sax\_exceptions.pyc

byte-compiling C:\Python23\lib\site-packages\_xmlplus\sax\handler.py to xml\sax\

handler.pyc

byte-compiling C:\Python23\lib\site-packages\_xmlplus\sax\sax2exts.py to xml\sax

\sax2exts.pyc

byte-compiling C:\Python23\lib\site-packages\_xmlplus\sax\saxexts.py to xml\sax\

saxexts.pyc

byte-compiling C:\Python23\lib\site-packages\_xmlplus\sax\saxlib.py to xml\sax\s

axlib.pyc

byte-compiling C:\Python23\lib\site-packages\_xmlplus\sax\saxutils.py to xml\sax

\saxutils.pyc

byte-compiling C:\Python23\lib\site-packages\_xmlplus\sax\xmlreader.py to xml\sa

x\xmlreader.pyc

>>>>>>>>>> 

 

Finally, here is the traceback data from the error:

>>>>>>>>>> 

J:\My Documents\My Projects\Python\yahtBGC\dist>yahtBGC

Traceback (most recent call last):

  File "yahtBGC.py", line 493, in ?

  File "yahtBGC.py", line 463, in yahtBGC

  File "yahtBGCscores.pyc", line 32, in __init__

  File "xml\marshal\generic.pyc", line 312, in load

  File "xml\marshal\generic.pyc", line 329, in _load

  File "xml\sax\saxexts.pyc", line 168, in make_parser

  File "xml\sax\saxexts.pyc", line 77, in make_parser

xml.sax._exceptions.SAXReaderNotAvailable: No parsers found

Exception exceptions.AttributeError: "'YahtBGCScores' object has no attribute

'scores'" in <bound method YahtBGCScores.__del__ of <yahtBGCscores.YahtBGCScores

object at 0x00A11FD0>> ignored

>>>>>>>>>> 

 

I looked through the maillist archives, and found a couple of threads that seemed to relate to this problem, but I’m afraid they weren’t much help to a novice like me.  Can someone point me toward a solution?

 

Regards,

 

Barry

barry.carroll@psc.com

541-302-1107

________________________

We who cut mere stones must always be envisioning cathedrals.

Quarry worker's creed