Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving 'ImportError: cannot import name etree' when using lxml in Python on Mac

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)

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.  

This error results from the line from lxml import etree.

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).

For reference:

  • Python Version: 2.7.2
  • Mac OS X 10.8.2

Thanks in advance for all the help.

like image 780
Craig Alleva Avatar asked Dec 06 '12 18:12

Craig Alleva


1 Answers

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'>
like image 147
Yuval Adam Avatar answered Oct 21 '22 14:10

Yuval Adam