python 在 mac os 10.10.1 上安装 lxml

标签 python macos python-2.7 scrapy lxml

我买了一台新的 macbook,我对 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 (2.8GB)。

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

xcode-select -p

你应该得到这样的东西:

/Applications/Xcode.app/Contents/Developer

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

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

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

pip install lxml

然后尝试再次运行scrapy

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

关于python 在 mac os 10.10.1 上安装 lxml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30410030/

相关文章:

python - 带有 opencv 的 matplotlib 给出具有相同像素值的不同图像

Python:在DataFrame中,在新列中为另一列中具有最高值的行添加值,并在第三列中添加相同的字符串

python - 无法学习如何查看字符串中的单个字符,检查大小写或数字

xcode - 我在Lion(Mac OS X 10.7.3)上安装了Xcode 4,但仍然找不到“make”命令

python-2.7 - peewee:重用动态创建的模型

python - 如何将 dict 转换为 unicode JSON 字符串?

cocoa - 在 Mac OS X 上的 Cocoa 中从 NSImage 获取 CGIImageRef

macos - 将 NSArrayController 的 ManagedObjectContext 设置为 nil 时崩溃

python - 如何在 Docker 中使用 Chrome 运行 Selenium

python - 我想要第 6 列值的总和