![](/img/trans.png)
[英]Parse XML into Pandas Dataframe, Python 3.8, ElementTree
[英]Unable to parse valid xml in cpython 3.8
我正在嘗試在 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 文件夾中。 我該如何解決? 或者我可以使用一些解決方法嗎? 在 elementtree 中使用 SimpleXMLTreeBuilder 的解決方案對我有用
我發現需要的 pyexpat.pyd 沒有復制到分發中。 我添加了解決我的問題的廣告
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.