python 在 mac os 10.10.1 上安装 lxml

python install lxml on mac os 10.10.1

我买了一本新的 mac 书,我对 mac os 很陌生。但是,我在网上读了很多关于如何安装 scrap

我什么都做了,但安装 lxml 时遇到问题

我在终端上试过了

pip install lxml

很多东西开始下载,终端上写了很多文字,但我在终端上收到了红色的错误消息

1 error generated.

error: command '/usr/bin/clang' failed with exit status 1

----------------------------------------
Cleaning up...
Command /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c "import setuptools, tokenize;__file__='/private/var/folders/rd/fxgsy46j3l77f6l9h_hv2fjm0000gn/T/pip_build_mycomputername/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/rd/fxgsy46j3l77f6l9h_hv2fjm0000gn/T/pip-WvDTPQ-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /private/var/folders/rd/fxgsy46j3l77f6l9h_hv2fjm0000gn/T/pip_build_mycomputername/lxml
Storing debug log for failure in /Users/mycomputername/.pip/pip.log

现在当我用 lxml 调用 scrapy spider 时,我收到了这条错误消息

ImportError: No module named lxml.html

请问我该怎么办?

欢迎任何建议

这可能是因为您在升级后没有重新安装命令行工具。

通常XCode应该升级到最新版本(4.4)(我相信当我更新到10.8时我也更新了一大堆其他应用程序,包括XCode)。更新后,您需要重新安装命令行工具。现在可以通过 XCode:

中的设置来完成

转到 "Preferences -> Downloads" 并安装 "Command Line Tools"。

我遇到了那个问题,我所做的是:

从苹果商店安装了所有 xcode (2.8GB)。

确保安装成功:打开终端并输入

xcode-select -p

你应该得到这样的东西:

/Applications/Xcode.app/Contents/Developer

现在您需要安装命令行工具。尝试在终端上输入 gcc,然后有两种可能性:要么你得到一个 window 要求安装工具,你必须点击 install,否则你会得到一个错误留言。

如果您收到错误消息,请不要担心,只需尝试使用此命令安装工具即可 xcode-select --install

之后重新启动 mac 然后像这样重新安装 lxml :

pip install lxml

然后再次尝试 运行 scrapy

如果您在任何其他库上遇到任何其他错误,只需使用 easy_installNOT 使用 pip 轻松重新安装 scrapy