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

问题描述 投票:1回答:1

我发现了一件奇怪的事。当我通过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

)

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

python python-2.7 xml-parsing py2exe
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.