使用IronPython时导入错误lxml

问题描述 投票:0回答:1

我正在使用python上的lxml模块成功解析xml文件。在IronPython上运行相同的代码时,它会出现像ImportError: cannot import etree from lxml这样的错误。我已经安装了lxml模块。任何想法?提前致谢...

python-2.7 lxml ironpython
1个回答
2
投票

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

这可能不会解决您的问题,但它可能会使它更清楚。

© www.soinside.com 2019 - 2024. All rights reserved.