SSL backend error when using OpenSSL

2019-01-13 02:44发布

I was trying to install pycurl in a virtualenv using pip and I got this error

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

I read some documentation saying that "To fix this, you need to tell setup.py what SSL backend is used" (source) although I am not sure how to do this since I installed pycurl using pip.

How can I specify the SSL backend when installing pycurl with pip?

Thanks

21条回答
做个烂人
2楼-- · 2019-01-13 03:25

Error:

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

This worked for me, Mac 10.13, python 3.5, pycurl import worked after installing like this

pip3 uninstall pycurl;

pip3 install --compile --install-option="--with-openssl" pycurl
查看更多
甜甜的少女心
3楼-- · 2019-01-13 03:27

Reinstallation of curl

I tried every suggestion from this discussion but no one worked for me. As solution I have reinstalled curl and curlib. After that I was able to install pycurl with ssl support inside environment.

At start:

'PycURL/7.43.0 libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3'

Part 1.Re/Installation with pip

Firstly I have removed pycurl from virtualenv using pip as was suggested previous answers:

pip uninstall pycurl
export PYCURL_SSL_LIBRARY=openssl
pip install pycurl --global-option="--with-openssl"

The idea here is that package was cached and we just reintstall it with openssl option.

I also tried to recompile pycurl with pip using:

pip install pycurl --compile pycurl --no-cache

..but had the same error after running:

python
import pycurl
pycurl.version

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

Part 2. Installation from tar

After previous method didn't work I have decidede to install pycurl from tar with:

curl -O https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz
sudo tar -xzvf pycurl-7.43.0.tar.gz
cd pycurl-7.43.0/
sudo python setup.py --with-ssl install

It has installed pycurl globally but not within virtualenv. I also didn't check if it was installed with SSL support or not but think that still without ssl.

Part 3. Reinstallation of curl and curllib

Finally I understood that pycurl doesn't installs normally into environment because global curl and libcurl are compiled with gnutls.

Before starting check it with:

curl-config --configure

One of the output lines will be

'--without-ssl' '--with-gnutls'

To recompile it:

Firstly remove curl:

sudo apt-get purge curl

Install any build dependencies needed for curl

sudo apt-get build-dep curl

Get latest (as of Dec 20, 2016) libcurl

mkdir ~/curl
wget http://curl.haxx.se/download/curl-7.51.0.tar.bz2
tar -xvjf curl-7.51.0.tar.bz2
cd curl-7.51.0

The usual steps for building an app from source

./configure
./make
 sudo make install

If openssl installed correctly then configure will find it automatically. The output will be:

curl version: 7.51.0
Host setup: x86_64-pc-linux-gnu
Install prefix: /usr/local
Compiler: gcc
SSL support: enabled (OpenSSL) ...

Resolve any issues of C-level lib location caches ("shared library cache")

sudo ldconfig

Now try to reinstall pycurl within environment:

curl -O https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz
pip install pycurl-7.43.0.tar.gz --global-option="--with-openssl"

The result should be:

python
import pycurl
pycurl.version

'PycURL/7.43.0 libcurl/7.51.0 OpenSSL/1.0.2g zlib/1.2.8 librtmp/2.3'

查看更多
可以哭但决不认输i
4楼-- · 2019-01-13 03:27

Not sure if this is because of running in a virtualenv, but on CentOS 7 these solutions weren't working for me; the compiled objects were still being grabbed from the cache dir when I was reinstalling. If you're running into the same problem after trying other solutions here, try the following:

pip uninstall pycurl
export PYCURL_SSL_LIBRARY=[nss|openssl|ssl|gnutls]
pip install pycurl --no-cache-dir
查看更多
看我几分像从前
5楼-- · 2019-01-13 03:28

I'm on CentOS 7. I tried all of the above and couldn't get anything to work. It turns out I needed to run these as a root user. So if you're having trouble, try any of the above solutions as a root user. As an example, here is what worked for me:

su -
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=[nss|openssl|ssl|gnutls]
pip install pycurl

Of course, all the usual disclaimers about running as a root user apply.

Note: [nss|openssl|ssl|gnutls] in the code above means to pick one, and don't include the square brackets or pipes. The person who asked the original question would have chosen openssl. In my particular case, I chose nss. Your error message should tell you which choice to make.

查看更多
贼婆χ
6楼-- · 2019-01-13 03:29

This worked for me:

pip uninstall pycurl
export PYCURL_SSL_LIBRARY=nss
easy_install pycurl

None of this worked for me (note the difference is simply easy_install vs pip):

pip uninstall pycurl
export PYCURL_SSL_LIBRARY=[nss|openssl|ssl|gnutls]
pip install pycurl
#xor
curl -O https://pypi.python.org/packages/source/p/pycurl/pycurl-7.19.3.1.tar.gz
#...
python setup.py --with-[nss|openssl|ssl|gnutls] install
查看更多
Deceive 欺骗
7楼-- · 2019-01-13 03:34

helloworld2013's answer is correct, but the key is matching the SSL library that pycurl is expecting. The error will be something like:

pycurl: libcurl link-time ssl backend (<library>) is different from compile-time ssl backend (<library> or "none/other")

To fix it, you have to use the library pycurl is expecting. In my case, my error was "pycurl: libcurl link-time ssl backend (nss) is different from compile-time ssl backend (openssl)", so my fix was:

pip uninstall pycurl
export PYCURL_SSL_LIBRARY=nss
pip install pycurl
查看更多
登录 后发表回答