【发布时间】: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