mac下使用pip安装pycurl引发的一系列问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nellyp/article/details/80110599

妈的,我要先骂几句娘,花了整整半天时间,太费劲了。。。

故事的开始

pycurl: libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other)

这个错遇到很多次了,Ubuntu和centOS上都很轻松的解决,直到在Mac上。。。。
这个问题有两种解决办法,先说没坑的

build it with NSS

重新编译libcurl,配置时加上参数

$ ./configure --without-ssl --with-nss

这样可以解决问题,并且不会踩其他的坑。
然后坑的来了

build it with openssl

当你决定使用openssl时,当你import pycurl时,首先你会遇到这个错:

pycurl: libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other)

好,那就解决它

pip uninstall pycurl
export PYCURL_SSL_LIBRARY=openssl
pip install pycurl

在第三步时,你会遇到下面的会心一击

'openssl/ssl.h' file not found

fuuuuuuck。。。
看报错是头文件没有了,马上去/usr/include里看,呵,果然没有openssl这个目录,更别说ssl.h头文件了。
然后我试着输入openssl命令,艹,绝对安装了啊,好,找到他,把include目录拷过去。你猜怎么着,sudo也不允许。果然事情不会这么简单,你就是root权限在Mac里也别想为所欲为。赶紧Google看看有别的辙没,这时候了解到MacOS的最新版本中不再提供openssl,嗯,nice。。。
看了Google上大家的思路,都是从PATH上下功夫指向已安装的目录。

最终的解决办法

首先,要找到你的Mac上openssl的安装目录,我用的是brew安装的,在我这里目录是

/usr/local/Cellar/openssl/1.0.2o_1

如果不清楚目录在哪,或者干脆没有安装

brew install openssl
brew info openssl

这样可以得到{安装目录},下面的 {安装目录} = /usr/local/Cellar/openssl/1.0.2o_1
接下来在你的bashrc或者zshrc中,添加

# openssl
LD_LIBRARY_PATH={安装目录}/lib:"${LD_LIBRARY_PATH}"
CPATH={安装目录}/include:"${CPATH}"
PKG_CONFIG_PATH={安装目录}/lib/pkgconfig:"${PKG_CONFIG_PATH}"
export LD_LIBRARY_PATH CPATH PKG_CONFIG_PATH
export LDFLAGS=-L{安装目录}/lib
export CPPFLAGS=-I{安装目录}/include

保存后,source, 再次执行一遍下面的命令

pip uninstall pycurl# 卸载包
export PYCURL_SSL_LIBRARY=openssl
pip install pycurl --compile --no-cache-dir# 重新编译安装

好了,总算把坑都踩了,妈个鸡

猜你喜欢

转载自blog.csdn.net/nellyp/article/details/80110599