前言
记录macos
安装pycurl
过程中的爬坑过程。
爬坑过程记录
本来目的是安装pyspider
的, 安装pyspider
必须依赖pycurl
。
本人环境:
- Python 3.6.4
- MacOS 10.12 Sierra
初次安装 pycurl
第一次安装pycurl。直接 pip
安装
pip install pycurl
可是安装并不顺利。安装报错:
...
File "/private/var/folders/nx/khfvbh1d6vg334173fsxzb9r0000gn/T/pip-install-y_b53n5l/pycurl/setup.py", line 316, in configure_unix
specify the SSL backend manually.''')
__main__.ConfigurationError: Curl is configured to use SSL, but we have not been able to determine which SSL backend it is using. Please see PycURL documentation for how to specify the SSL backend manually.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/nx/khfvbh1d6vg334173fsxzb9r0000gn/T/pip-install-y_b53n5l/pycurl/
可以看到报错应该是因为 使用ssl配置的原因。查看官方PycURL Installation¶,可以不使用ssl安装。
第二次安装 pycurl
第二次安装,配置不使用ssl安装。
# upgrade pip if necessary
pip install --upgrade pip
# remove current pycurl
pip uninstall pycurl
# set PYCURL_SSL_LIBRARY
export PYCURL_SSL_LIBRARY=nss
# recompile and install pycurl
pip install --compile pycurl
可是还是报错:
...
build/temp.macosx-10.12-x86_64-3.6/src/stringcompat.o build/temp.macosx-10.12-x86_64-3.6/src/threadsupport.o build/temp.macosx-10.12-x86_64-3.6/src/util.o -lssl3 -lcurl -o build/lib.macosx-10.12-x86_64-3.6/pycurl.cpython-36m-darwin.so
ld: library not found for -lssl3
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1
----------------------------------------
Command "/Users/chenruiwen/.pyenv/versions/3.6.4/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/nx/khfvbh1d6vg334173fsxzb9r0000gn/T/pip-install-syesb72n/pycurl/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/nx/khfvbh1d6vg334173fsxzb9r0000gn/T/pip-record-ch2zxgp5/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/nx/khfvbh1d6vg334173fsxzb9r0000gn/T/pip-install-syesb72n/pycurl/
二次吐血。
第三次安装pycurl
还是根据官网,nss
不可以,配置成openssl
试试吧。
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=openssl
pip install --compile pycurl
还是那个熟悉的味道:
...
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Cellar/openssl/1.0.2o_1/include -DPYCURL_VERSION="7.43.0.2" -DHAVE_CURL_SSL=1 -DHAVE_CURL_OPENSSL=1 -DHAVE_CURL_SSL=1 -I/Users/chenruiwen/.pyenv/versions/3.6.4/include/python3.6m -c src/docstrings.c -o build/temp.macosx-10.12-x86_64-3.6/src/docstrings.o
In file included from src/docstrings.c:4:
src/pycurl.h:164:13: fatal error: 'openssl/ssl.h' file not found
# include <openssl/ssl.h>
^~~~~~~~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
----------------------------------------
Command "/Users/chenruiwen/.pyenv/versions/3.6.4/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/nx/khfvbh1d6vg334173fsxzb9r0000gn/T/pip-install-aavrg23s/pycurl/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/nx/khfvbh1d6vg334173fsxzb9r0000gn/T/pip-record-l0npewt_/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/nx/khfvbh1d6vg334173fsxzb9r0000gn/T/pip-install-aavrg23s/pycurl/
三次吐血。可以看到引入 openssl/ssl.h
失败了。继续google解决一下。
第四次安装pycurl
从 stackoverflow
搜到一个解决方案,准备尝试一下。
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=openssl
export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include
pip install pycurl --compile --no-cache-dir
果然安装成功了!可喜可贺!可是我们用python导入pycurl试试:
>>> import pycurl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: pycurl: libcurl link-time ssl backend (none/other) is different from compile-time ssl backend (openssl)
四次吐血。 不过这次的问题应该是系统版本问题,刚刚 stackoverflow
上的解决方案要求是系统OSX 10.13
,于是乎备份系统,升级到macOS 10.13 High Sierra
。 大胆的童鞋可以不备份升级,比如我(:D)。
升级完成后尝试一下导入pycurl:
>>> import pycurl
>>>
成功解决问题。吐血完毕。