简体   繁体   中英

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

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

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 .

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.

sudo env ARCHFLAGS="-arch x86_64" easy_install-2.7 lxml

适用于Mac OS 10.9。

STATIC_DEPS=true sudo pip install lxml

它的工作原理见http://lxml.de/build.html#building-lxml-on-macos-x

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM