我目前正在使用Mac OS X 10.11.1 El Capitan。我在我的mac上安装了python 2.7和3.5。我也安装了pip。但是,我总是无法在我的Mac上安装scrapy。
我用过
$sudo pip install scrapy
并且始终发现错误。 (像这样)
1 error generated.
Compile failed: command 'cc' failed with exit status 1
creating tmp
cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitOS_E4M.c -o tmp/xmlXPathInitOS_E4M.o
/tmp/xmlXPathInitOS_E4M.c:1:10: fatal error: 'libxml/xpath.h' file not found
#include "libxml/xpath.h"
^
1 error generated.
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
Perhaps try: xcode-select --install
*********************************************************************************
error: command 'cc' failed with exit status 1
和... ..
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-veAN2s/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-8tLCDw-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-veAN2s/lxml
任何人都可以告诉我问题和解决方案是什么?
答案 0 :(得分:9)
xcode-select --install
自升级以来,您可能尚未更新代码命令行工具。
答案 1 :(得分:1)
问题是您的MacOS与其默认的Python2链接,后者又错过了适当的GCC标志来编译Scrapy。
我想你已经安装了Homebrew,然后执行以下操作:
brew install python
pip install --upgrade pip setuptools
pip install scrapy
答案 2 :(得分:1)
在尝试了所有上述步骤后仍然失败的情况,如果您使用的是Mojave和pypy3虚拟环境,那么这是我的:
(env)$python -V
Python 3.5.3 (fdd60ed87e94, Apr 24 2018, 06:10:18)
[PyPy 6.0.0 with GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]
(env)$ pip -V
pip 18.1 from xxx/xxx/pip (python 3.5)
指出以下几点:
export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib
来源:
https://github.com/pyca/cryptography/issues/3489
希望对您有所帮助。
答案 3 :(得分:0)
尝试easy install
。在安装和卸载Python 3后,我很难安装scrapy
。easy install
解决了我的问题。
答案 4 :(得分:-1)
须藤 C_INCLUDE_PATH = /应用/ Xcode.app /内容/开发/平台/ MacOSX.platform /开发商/软件开发工具包/ MacOSX10.11.sdk / usr / include目录/ libxml2的 :/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/libxml :/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include pip install scrapy --ignore-installed six
关闭SIP(系统完整性保护) - 然后重启,使用命令+ R进入调试模式,然后选择终端: csrutil禁用 重启
重新安装六个 - 然后删除旧的六,重新安装
sudo rm -rf /Library/Python/2.7/site-packages/six *
sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six *
sudo pip install six
然后scrapy工作