使用IronPython时导入错误lxml

时间:2019-04-19 12:10:45

标签: python-2.7 lxml ironpython

我正在使用python上的lxml模块成功解析xml文件。在IronPython上运行相同的代码时,会出现类似ImportError: cannot import etree from lxml的错误。我已经安装了lxml模块。预先感谢...

1 个答案:

答案 0 :(得分:1)

我建议您修改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")

这可能无法解决您的问题,但可以使问题更加清楚。