本文介绍了在Mac上的Python中使用lxml时,收到"ImportError:无法导入名称etree"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac上为Python正确安装lxml时遇到困难.我已按照此处的说明进行操作,该说明在安装后表明安装成功(但是,一些警告.有关安装和警告的完整日志,请此处))

I'm having difficulty properly installing lxml for Python on Mac. I have followed the instructions here, which after installation indicates that the installation is successful (however, there are some warnings. The full log of the install and warnings can be found here)

运行安装后,我试图在lxml安装目录中运行Test.py以确保其正常运行.我立即收到错误提示:

After running the install, I am trying to run Test.py in the lxml install directory to ensure that it's working correctly. I am immediately prompted with the error:

ImportError"  cannot import name etree.  

此错误是由于from lxml import etree行引起的.

This error results from the line from lxml import etree.

在看似成功的安装之后,我似乎无法弄清楚为什么它在这里失败.请原谅我的无知,因为我通常不使用Python编程,当然也绝不使用MAC(目前被迫这样做).

I can't seem to figure out why it's failing here after a seemingly successful install. Please forgive my ignorance, as I don't typically program in Python and certainly never on a MAC (forced to do so at the moment).

供参考:

  • Python版本:2.7.2
  • Mac OS X 10.8.2

预先感谢所有帮助.

推荐答案

听起来像您的路径中还有另一个lxml.确保您引用的是正确的,它应该看起来像这样:

Sounds like you have another lxml in your path. Make sure you are referencing the right one, it should look something like this:

>>> import lxml
>>> lxml
<module 'lxml' from '/path/to/lib/python2.7/site-packages/lxml/__init__.pyc'>

这篇关于在Mac上的Python中使用lxml时,收到"ImportError:无法导入名称etree"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 08:37