在SSL为s之后安装pycurl时发生SSL错误

2024-04-18 22:00:39 发布

您现在位置:Python中文网/ 问答频道 /正文

只需要一些信息:

  • 我在运行MacOS10.7.5
  • 我已经安装了curl 7.21.4(我相信它附带了开发工具)
  • 我有python 2.7.1

我一直在尝试安装pycurl,但每次尝试运行它时,我都会得到:

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

我首先使用以下设置安装pycurl:

python setup.py install

它不起作用(因为没有配置SSL)。

在尝试以下操作之前,我已经卸载了pycurl(sudo rm -rf /Library/Python/2.7/site-packages/pycurl*):

export PYCURL_SSL_LIBRARY=openssl
easy-install pycurl

再次尝试之前:

python setup.py --with-ssl install

但是,我仍然得到与ssl未编译时相同的错误。好像所有的指令都忽略了我的尝试。

setup.py在安装时一点也不抱怨,但是easy install在我设置PYCURL_SSL_LIBRARY env var之后会打印此消息:

src/pycurl.c:151:4: warning: #warning "libcurl was compiled with SSL support, but configure could not determine which " "library was used; thus no SSL crypto locking callbacks will be set, which may " "cause random crashes on SSL requests"

这似乎表明它完全忽略了我刚刚告诉它用openssl安装的事实。。。

有什么东西我在设置中遗漏了吗?


Tags: installpybackendssltimewitheasysetup
3条回答

当你得到:
failed: ImportError: pycurl: libcurl link-time ssl backend (nss) is different from compile-time ssl backend (none/other)

您需要使用正确设置的pycurl_SSL_库重新编译pycurl。 重新安装似乎是一个两阶段的过程。

pip似乎将这些东西下载到某个地方,编译后放到python可以使用的地方。 如果你在缓存中有编译过的版本,你会被彻底搞砸,因为它不会重新编译。它“给”python同样的东西,不管PYCURL_SSL_LIBRARY变量中是什么。

解决方案非常简单,删除缓存以强制其重新编译。根据操作系统的不同,缓存可能位于多个位置。您可以使用setup.py来搜索它。它包含PACKAGE=“pycurl”字符串。但没必要这么麻烦。最新的pip版本支持install--compile选项。

升级至最新pip:
pip install --upgrade pip #Healthy anyway

使用以下命令删除当前pycurl:
pip uninstall pycurl

根据需要设置PYCURL_SSL_库:
export PYCURL_SSL_LIBRARY=nss #For me this was the required setting

最后运行
pip install --compile pycurl

注意,对于编译过程中需要的各种头文件,可能需要一些-devel包。

我必须在CentOS 7上使用以下命令:

sudo pip install --no-cache-dir --compile --ignore-installed --install-option="--with-nss" pycurl

不需要uninstall或设置PYCURL_SSL_LIBRARY。所有的东西都被烤成一条线。

您还需要openssl的“开发工具”(headers/libraries)。

也可以尝试pycurl的最后一个版本,它可能是开箱即用的。

相关问题 更多 >