我想安装Lxml,这样我就可以安装Scrapy了。

当我更新我的Mac今天,它不让我重新安装lxml,我得到以下错误:

In file included from src/lxml/lxml.etree.c:314:
/private/tmp/pip_build_root/lxml/src/lxml/includes/etree_defs.h:9:10: fatal error: 'libxml/xmlversion.h' file not found
#include "libxml/xmlversion.h"
         ^
1 error generated.
error: command 'cc' failed with exit status 1

我尝试使用brew安装libxml2和libxslt,两者都安装好了,但我仍然无法安装lxml。

上次安装时,我需要在Xcode上启用开发人员工具,但由于它更新到Xcode 5,它不再给我这个选项了。

有人知道我要做什么吗?


当前回答

在编译之前,将xmlversion.h的路径添加到您的环境中。

$ set INCLUDE=$INCLUDE:/private/tmp/pip_build_root/lxml/src/lxml/

但是要确保我提供的路径中有xmlversion.h文件。然后,

$ python setup.py install

其他回答

在咬着牙撕扯头发之后,我用pip卸载了Xcode,然后运行:

easy_install lxml

一切都很好。

我遇到了同样的问题,经过几天的工作,我在OS X 10.9.4上用Python 3.4.1解决了这个问题。

这是我的解决方案,

根据从lxml.de安装lxml,

lxml的macport是可用的。尝试端口安装py25-lxml之类的方法

如果没有MacPort,请从MacPort.org上安装。这很简单。你可能还需要一个编译器,安装Xcode编译工具,使用Xcode -select——install

首先,我通过sudo port selfupdate将我的端口更新到最新版本,

然后我只是键入sudo端口安装libxml2,几分钟后,你应该看到libxml2安装成功。可能还需要libxslt来安装lxml。要安装libxslt,请使用:sudo port install libxslt。

现在,只需输入pip install lxml,它应该可以正常工作。

Try:

% STATIC_DEPS=true pip install lxml

Or:

% STATIC_DEPS=true sudo pip install lxml

它的工作原理!

xcode-select --install
sudo easy_install pip
sudo pip install lxml

你应该安装或升级Xcode的命令行工具。 在终端试试这个:

xcode-select --install