Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

python - import lxml fails on OSX after (seemingly) successful install

I'm trying to install lxml for python on OS X 10.6.8

I ran sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml in the terminal based on this answer to a question installing lxml: https://stackoverflow.com/a/6545556/216336

This was the output of that command:

MYCOMPUTER:~ MYUSERNAME$ sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml
Password:
Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.3.3
Downloading http://lxml.de/files/lxml-2.3.3.tgz
Processing lxml-2.3.3.tgz
Running lxml-2.3.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ytPLAc/lxml-2.3.3/egg-dist-tmp-NgYLdF
Building lxml version 2.3.3.
Building without Cython.
Using build configuration of libxslt 1.1.24
Adding lxml 2.3.3 to easy-install.pth file

Installed /Library/Python/2.6/site-packages/lxml-2.3.3-py2.6-macosx-10.6-universal.egg
Processing dependencies for lxml
Finished processing dependencies for lxml

Which looked successful to me, but I get an import error when I try to import lxml in python...

Last login: Sat Mar 24 15:26:04 on ttys000
MYCOMPUTER:~ MYUSERNAME$ python2.7
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named lxml

The fact that I it appears to have installed to 2.6 and I'm running 2.7 seems to be a clue, but I don't know what to do with that.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You've installed a newer version of Python (2.7.2) but you also need to install and use a copy of easy_install (from Distribute or setuptools) to use with it. You ended up using the default Apple-supplied version of easy_install associated with the Apple-supplied Python 2.6. Note the /Library/Python/2.6 in the easy_install output. (You can verify that by trying to import lxml when using /usr/bin/python2.6.) After you install easy_install using your Python 2.7, the new easy_install should be first on your shell path if you used the standard python.org installer defaults. If not, update your PATH:

export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

Then easy_install lxmlusing it. With the python.org 2.7.2, you shouldn't need to add the ARCHFLAGS environment variable but it doesn't hurt.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...