Python 2.7:xml.sax._exceptions.SAXReaderNotAvailable:找不到解析器

时间:2014-05-25 14:30:36

标签: python python-2.7 xml-parsing

我发现了一件奇怪的事。当我通过PyCharm运行python代码时,我的应用程序运行正常。但是,当我通过py2exe应用程序执行exe文件时出现错误:

Traceback (most recent call last):
  File "main.py", line 23, in CreateNewClientRequest
  File "suds\client.pyc", line 112, in __init__
  File "suds\reader.pyc", line 152, in open
  File "suds\wsdl.pyc", line 136, in __init__
  File "suds\reader.pyc", line 79, in open
  File "suds\reader.pyc", line 101, in download
  File "suds\sax\parser.pyc", line 127, in parse
  File "suds\sax\parser.pyc", line 111, in saxparser
  File "xml\sax\sax2exts.pyc", line 37, in make_parser
  File "xml\sax\saxexts.pyc", line 77, in make_parser
xml.sax._exceptions.SAXReaderNotAvailable: No parsers found

有谁知道如何解决这个问题? 这是我的python代码示例(可能有帮助):

# -*- coding: UTF-8 -*-

import sys, xml
from PyQt4 import QtGui
from window import Ui_SmartRequest
from suds.client import Client

class Main(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_SmartRequest()
        self.ui.setupUi(self)
        self.ui.btn.clicked.connect(self.CreateNewClientRequest)

    def CreateNewClientRequest(self):
        shop = self.ui.shop_line.text()
        shop1 = "%s" %shop
        card_id = self.ui.card_line.text()
        card_id1 = "%s" %card_id
        anketa = self.ui.anketa_line.text()
        anketa1 = "%s" %anketa
        client = Client('http://172.16.0.37:8000/CardPort?wsdl')
        out = client.service.CreateNewClientRequest(shop1, card_id1, anketa1)
        out1 = "%s" %out
        out2 = str(out1[19:38])
        out3 = out2.replace("}", "")
        self.ui.line_out.setText("Code:"+out3)

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    window = Main()
    window.show()
    sys.exit(app.exec_())

还有来自setup.py的代码:

from distutils.core import setup
import py2exe

setup(
    windows=[{"script":"main.py"}],
    options={"py2exe": {"includes":["PyQt4","sip","suds","sys","os","wstools","defusedxml", "xml.sax"]}},
    zipfile=None

)

如果有人帮助我,我会很高兴的!

1 个答案:

答案 0 :(得分:0)

如果你正在

文件" xml \ sax \ saxexts.pyc",第77行,在make_parser中 xml.sax._exceptions.SAXReaderNotAvailable:找不到解析器 尝试将此添加到您的setup.py py2exe命令行:

--packages xml.sax.drivers,xml.sax.drivers2

来源:http://www.py2exe.org/index.cgi/Py2exeAndPyXML