我想安装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,它不再给我这个选项了。

有人知道我要做什么吗?


当前回答

我试了这一页上所有的答案,没有一个对我有用。我运行的是OS X版本10.9.2

但这绝对有效....像个符咒:

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install lxml

其他回答

从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,则省略此选项。

全球安装…OS x 10.9.2

xcode-select --install
sudo easy_install pip
sudo CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install lxml

我试了这一页上所有的答案,没有一个对我有用。我运行的是OS X版本10.9.2

但这绝对有效....像个符咒:

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install lxml

我使用OSX 10.9.2,我得到了同样的错误。

安装Xcode命令行工具对这个特定版本的OSX没有帮助。

我认为更好的解决方法是使用以下命令进行安装:

$ CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 pip install lxml

这类似于jdkoftinoff的修复,但不会永久地改变您的系统。

这也困扰了我一段时间。我不太了解python distutils等的内部原理,但这里的include路径是错误的。我做了以下丑陋的hack,直到python lxml的人能做适当的修复。

sudo ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2/libxml/ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml