使用 IronPython 时导入错误 lxml
Import error lxml when working with IronPython
我正在 python 上使用 lxml 模块成功解析 xml 文件。当 运行 IronPython 上的相同代码出现 ImportError: cannot import etree from lxml
之类的错误时。我已经安装了 lxml module.Any 想法?提前致谢...
我建议您修改 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")
这可能不会解决您的问题,但它可能会让问题所在更清楚。
我正在 python 上使用 lxml 模块成功解析 xml 文件。当 运行 IronPython 上的相同代码出现 ImportError: cannot import etree from lxml
之类的错误时。我已经安装了 lxml module.Any 想法?提前致谢...
我建议您修改 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")
这可能不会解决您的问题,但它可能会让问题所在更清楚。