问题描述
我正在尝试解析 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,line 1505,in __init__
ImportError: No module named expat; use SimpleXMLTreeBuilder instead
Error parsing script
但是pyexpat.pyd存在于cpython的lib文件夹中。我该如何解决?或者我可以使用一些解决方法吗? Using SimpleXMLTreeBuilder in elementtree 的解决方案对我有用
解决方法
我发现所需的 pyexpat.pyd 没有复制到发行版中。我添加的广告解决了我的问题