【问题标题】:Unable to parse valid xml in cpython 3.8无法在 cpython 3.8 中解析有效的 xml
【发布时间】:2021-04-07 15:22:49
【问题描述】:

我正在尝试在 Python 脚本中解析 xml 文件,该脚本在 C++ 应用程序中运行。当我尝试运行此脚本时:

import xml.etree.ElementTree as ET
root = ET.parse('somexml.xml' ).getroot()

我总是收到错误:

RunScriptFail: Traceback (most recent call last):
  File "xml\etree\ElementTree.py", line 1500, in __init__
  File "<frozen zipimport>", line 259, in load_module
  File "xml\parsers\expat.py", line 4, in <module>
ModuleNotFoundError: No module named 'pyexpat'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "xml\etree\ElementTree.py", line 1503, in __init__
ModuleNotFoundError: No module named 'pyexpat'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "xml\etree\ElementTree.py", line 1202, in parse
  File "xml\etree\ElementTree.py", line 589, in parse
  File "xml\etree\ElementTree.py", line 1505, in __init__
ImportError: No module named expat; use SimpleXMLTreeBuilder instead

Error parsing script

但是 pyexpat.pyd 存在于 cpython 的 lib 文件夹中。我该如何解决?或者我可以使用一些解决方法吗? Using SimpleXMLTreeBuilder in elementtree 的解决方案适合我

【问题讨论】:

    标签: python-3.x xml cpython


    【解决方案1】:

    我发现需要的 pyexpat.pyd 没有复制到分发中。我添加了解决我的问题的广告

    【讨论】:

      猜你喜欢
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      • 1970-01-01
      • 2012-04-09
      • 2022-08-08
      • 1970-01-01
      相关资源
      最近更新 更多