Python 无法在 Mac os x 10.9 上安装 Lxml

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19548011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:01:15  来源:igfitidea点击:

Cannot install Lxml on Mac os x 10.9

pythonxcodemacosscrapylxml

提问by David O'Regan

I want to install Lxml so I can then install Scrapy.

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

When I updated my Mac today it wouldn't let me reinstall lxml, I get the following error:

当我今天更新我的 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

I have tried using brew to install libxml2 and libxslt, both installed fine but I still cannot install lxml.

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

Last time I was installing I needed to enable the developer tools on Xcode but since its updated to Xcode 5 it doesnt give me that option anymore.

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

Does anyone know what I need to do?

有谁知道我需要做什么?

采纳答案by tinylee

You should install or upgrade the commandline tool for xcode. Try this in a terminal:

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

xcode-select --install

回答by jdkoftinoff

This has been bothering me as well for a while. I don't know the internals enough about python distutils etc, but the include path here is wrong. I made the following ugly hack to hold me over until the python lxml people can do the proper fix.

这也困扰了我一段时间。我对 python distutils 等的内部了解不够,但这里的包含路径是错误的。我做了以下丑陋的 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

回答by André Augusto

You may solve your problem by running this on the commandline:

您可以通过在命令行上运行来解决您的问题:

 STATIC_DEPS=true pip install lxml

It sure helped me. Explanations on docs

它确实帮助了我。文档说明

回答by Geek4IT

Try:

尝试:

% STATIC_DEPS=true pip install lxml

Or:

或者:

% STATIC_DEPS=true sudo pip install lxml

It works!

有用!

回答by valo

I am using OSX 10.9.2 and I get the same error.

我正在使用 OSX 10.9.2,但出现相同的错误。

Installation of the XCode command line tools does not help for this particular version of OSX.

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

I think a better approach to fix this is to install with the following command:

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

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

This is similar to jdkoftinoff' fix, but does not alter your system in a permanent way.

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

回答by panchicore

instalation instructions on http://lxml.de/installation.htmlexplain:

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

To speed up the build in test environments, e.g. on a continuous integration server, disable the C compiler optimisations by setting the CFLAGS environment variable:

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

CFLAGS="-O0" pip install lxml

回答by okigan

None of the above worked for me on 10.9.2, as compilation bails out with following error:

以上在 10.9.2 上都不适合我,因为编译会出现以下错误:

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

Which actually lead to cleanest solution (see more details in [1]):

这实际上导致了最干净的解决方案(请参阅 [1] 中的更多详细信息):

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

pip install lxml

or following if installing globally

或者如果全局安装,则遵循

sudo pip install lxml

[1] clang error: unknown argument: '-mno-fused-madd' (python package installation failure)

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

回答by npiv

OSX 10.9.2

OSX 10.9.2

sudo env ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future STATIC_DEPS=true pip install lxml

回答by Samy Vilar

Installing globally... OS X 10.9.2

全局安装... 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

回答by Hexatonic

I tried all the answers on this page, none of them worked for me. I'm running OS X Version 10.9.2

我尝试了此页面上的所有答案,但没有一个对我有用。我正在运行 OS X 版本 10.9.2

But this definitely works....like a charm:

但这绝对有效......就像一个魅力:

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

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