我想安装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

其他回答

以上这些在10.9.2中都不适用,因为编译时会出现以下错误:

clang: error: unknown argument: '-mno-fused-madd' 

这实际上导致了最干净的解决方案(详见[1]):

export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments

pip install lxml

如果全局安装,则跟随

sudo pip install lxml

[1] clang错误:未知参数:'-mno-fused-madd' (python包安装失败)

http://lxml.de/installation.html上的安装说明说明:

为了在测试环境中加速构建,例如在持续集成服务器上,通过设置CFLAGS环境变量禁用C编译器优化:

CFLAGS="-O0" pip install lxml

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

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

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

$ python setup.py install

从pip (lxml 3.6.4)成功安装后,我在导入lxml时得到一个错误。etree模块。

我无休止地寻找安装这个作为scrapy的必要条件,并尝试了所有的选项,但最终这对我来说是有效的(mac osx 10.11 python 2.7):

$ STATIC_DEPS=true sudo easy_install-2.7 "lxml==2.3.5"

lxml的旧版本似乎与etree模块一起工作。

Pip通常可以忽略包的指定版本,例如当您在Pip缓存中有较新的版本时,因此easy_install。'-2.7'选项适用于python版本,如果您安装的是python 3.x,则省略此选项。

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

xcode-select --install