tags:

views:

52

answers:

3

The code

from lxml import etree 

produces the error

ImportError: No module named lxml 

Running

sudo easy_install lxml

results in

lxml 2.2.7 is already the active version in easy-install.pth 
Removing lxml-2.2.7-py2.5-macosx-10.3-i386.egg from site-packages and rerunning sudo easy_install lxml results in
Adding lxml 2.2.7 to easy-install.pth file
Installed /Library/Python/2.5/site-packages/lxml-2.2.7-py2.5-macosx-10.3-i386.egg
Processing dependencies for lxml
Finished processing dependencies for lxml

And yet I still get No module named lxml

What step am I missing in order to use lxml on my Mac (OSX 10.5)?

Update

python --version reports

Python 2.5.2

and running python produces

Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) 
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
A: 

You have multiple versions of python installed on your computer. lxml is installed for one, and you're invoking the other. There's not enough context to divine any more than that.

Aaron Gallagher
A: 

Some thing is not right here. The package being added is lxml-2.2.7-py2.5-macosx-10.3-i386.egg It refers to mac os x 10.3 , while you are using mac os x 10.5.

Try python --version, what does that tell you?

pyfunc
The `10.3` in the file name refers to the ABI (`MACOSX_DEPLOYMENT_TARGET`) of the Python instance used, not necessarily the OS X version you are running. For example, traditionally python.org OS X installers are built with `MACOSX_DEPLOYMENT_TARGET=10.3` so that the same installer and Python can be used on OSX 10.3 and above (including 10.5 and 10.6).
Ned Deily
+1  A: 

You appear to be trying to easy_install lxml into the Apple-supplied Python 2.5 for OS X 10.5 but using an egg that was likely built with a python.org Python 2.5. If you have both installed on your system, keep in mind that you need to have a separate easy_install (setuptools or Distribute) for each Python. Apple supplies one in /usr/bin for its Python. Ensuring that you are using the python.org one (check which python), you should follow the installation instructions for setuptools or Distribute to install an easy_install for it. That easy_install will be in the bin directory of the python.org framework: /Library/Frameworks/Python.framework/Versions/2.5//bin. Use that easy_install to install lxml; it should then automatically end up in /Library/Frameworks/Python.framework/Versions/2.5/lib. There is a more detailed discussion of a similar problem here and here.

Ned Deily