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

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

其他回答

这篇文章链接了一个对我有用的解决方案 在Mac OS X 10.9上,Python3, lxml和“Symbol not found: _lzma_auto_decoder”

hth

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

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

CFLAGS="-O0" 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的修复,但不会永久地改变您的系统。

我通过运行以下命令在Yosemite解决了这个问题:

xcode-select install #this may take several minutes.
pip install lxml

Try:

% STATIC_DEPS=true pip install lxml

Or:

% STATIC_DEPS=true sudo pip install lxml

它的工作原理!