导入lxml在OSX上失败,在(看起来)成功的ins之后

2024-05-19 19:28:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图在OSX10.6.8上安装lxml for python

我在终端中运行了sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml,这是基于对安装lxml的问题的回答:https://stackoverflow.com/a/6545556/216336

这是该命令的输出:

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

这看起来很成功,但当我尝试在python中导入lxml时,出现了一个导入错误。。。

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

事实上,我似乎已经安装到2.6,我运行的是2.7似乎是一个线索,但我不知道该怎么办。


Tags: installenvhttpforeggeasysudolxml
2条回答

你应该能跑:

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

这将使用2.7安装附带的easy_install版本。

您已经安装了新版本的Python(2.7.2),但还需要安装并使用easy_install(来自^{}setuptools)的副本来使用它。最终,您使用了与Apple提供的Python2.6相关联的默认Apple提供的easy_install版本。注意easy_install输出中的/Library/Python/2.6。(您可以在使用/usr/bin/python2.6时尝试导入lxml)在使用Python 2.7安装easy_install之后,如果使用标准Python.org安装程序默认值,那么新的easy_install应该首先位于shell路径上。如果没有,请更新您的PATH

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

然后easy_install lxml使用它。对于python.org 2.7.2,您不需要添加ARCHFLAGS环境变量,但它不会造成伤害。

相关问题 更多 >