【发布时间】:2019-04-19 12:10:44
【问题描述】:
我在 python 上使用 lxml 模块成功解析了一个 xml 文件。在 IronPython 上运行相同的代码时,会出现类似 ImportError: cannot import etree from lxml 的错误。我已经安装了 lxml 模块。知道吗?提前谢谢...
【问题讨论】:
标签: python-2.7 lxml ironpython
我在 python 上使用 lxml 模块成功解析了一个 xml 文件。在 IronPython 上运行相同的代码时,会出现类似 ImportError: cannot import etree from lxml 的错误。我已经安装了 lxml 模块。知道吗?提前谢谢...
【问题讨论】:
标签: python-2.7 lxml ironpython
我建议您修改 IronPython 中的代码来执行此操作(如 lxml tutorial 中所建议的那样)。
try:
from lxml import etree
print("running with lxml.etree")
except ImportError:
try:
# Python 2.5
import xml.etree.cElementTree as etree
print("running with cElementTree on Python 2.5+")
except ImportError:
try:
# Python 2.5
import xml.etree.ElementTree as etree
print("running with ElementTree on Python 2.5+")
except ImportError:
try:
# normal cElementTree install
import cElementTree as etree
print("running with cElementTree")
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as etree
print("running with ElementTree")
except ImportError:
print("Failed to import ElementTree from any known place")
这可能无法解决您的问题,但它可能会让您更清楚问题所在。
【讨论】: