Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems installing lxml on a Mac, it installs but module not found

Tags:

python

macos

lxml

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
like image 677
David Sykes Avatar asked Sep 02 '10 07:09

David Sykes


2 Answers

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.

like image 121
Ned Deily Avatar answered Oct 03 '22 10:10

Ned Deily


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.

like image 26
habnabit Avatar answered Oct 03 '22 12:10

habnabit