我试图让我的游戏运行起来。代码需要xml.sax。我用py2exe导入它,它仍然不想工作。我已经尝试了好几天而且我无法上班。在将它编译为.exe之前,它可以工作,但每当我将它编译为exe时,它都无法工作。
运行:
[ - ] Python 2.7.9 32位
[ - ] py2exe 0.6.9 32位
错误是:SAXReaderNotAvailable: No parsers found
这是我的游戏代码:
import xml.sax
class DNAError(Exception): pass
class DNAParseError(DNAError): pass
elementRegistry = {}
def registerElement(element):
elementRegistry[element.TAG] = element
class DNASaxHandler(xml.sax.ContentHandler):
def __init__(self):
xml.sax.ContentHandler.__init__(self)
self.stack = []
self.root = None
def startElement(self, tag, attrs):
if self.stack:
parent = self.stack[-1]
parentTag = parent.TAG
else:
parent = None
parentTag = None
element = elementRegistry.get(tag)
if not element:
raise DNAParseError('Unknown element type: ' + tag)
if parentTag not in element.PARENTS:
raise DNAParseError('Cannot put %s below %s element' % (tag, parentTag))
element = element(**attrs)
self.stack.append(element)
element.reparentTo(parent)
if not self.root:
self.root = element
def endElement(self, tag):
self.stack.pop(-1)
def characters(self, chars):
if not self.stack:
return
self.stack[-1].handleText(chars)
def parse(stream):
handler = DNASaxHandler()
xml.sax.parse(stream, handler)
return handler.root
这是py2exe的编译脚本:
from distutils.core import setup
import py2exe
setup(
options={"py2exe": {"includes": [ "xml.sax.drivers.*", "xml.sax.drivers2.*", "xml.sax" ] }},
zipfile = None,
windows = ['relived.py']
)
答案 0 :(得分:0)