SSL backend error when using OpenSSL
Asked Answered
E

26

89

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

Educable answered 13/1, 2014 at 16:33 Comment(1)
What is your OS?Frankpledge
E
125

for most people

After reading their INSTALLATION file, I was able to solve my problem by setting an environment variable and did a reinstall

# remove existing `pycurl` installation 
pip uninstall pycurl

# export variable with your link-time ssl backend (which is openssl above)
export PYCURL_SSL_LIBRARY=openssl

# then, re-install `pycurl` with **no cache**
pip install pycurl --no-cache-dir

There could be other solution out there but this works perfectly for me on a virtualenv and pip installation.

Some people have a different error message complaining about nss instead of openssl

ImportError: pycurl: libcurl link-time ssl backend (nss)

(the key part is nss) so you have to do something different for this error message:

pip uninstall pycurl
pip install --no-cache-dir --compile --compile-options="--with-nss" pycurl
Educable answered 13/1, 2014 at 19:1 Comment(6)
Thanks, PYCURL_SSL_LIBRARY=openssl works perfectly!Incogitable
For mac os x users: don't remember use set -x PYCURL_SSL_LIBRARY openssl instead of export PYCURL_SSL_LIBRARY=openssl if you use fish console instead of bash.Supination
pip install pycurl --no-cache-dirArbitrament
Thanks. I've looked through a number of potential solutions to this issue. This solution worked the first time.Trinatrinal
step by step virtualenv install example yippeecode.com/view-code/343QWQT144/…Educable
Except in my case had to use export PYCURL_SSL_LIBRARY=nss because this is what was installed on my system.Softpedal
R
79

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
Rhigolene answered 16/4, 2014 at 19:42 Comment(7)
Brilliant . This should get more votes . The original answer applied to some machines . This one is more general way to fix it depending on ur platform .Connor
hmm this didn't work for me on a mac. It seems like PYCURL_SSL_LIBRARY is being completely ignored. The compile-time ssl backend is always "(none/other)" for me, even though echo PYCURL_SSL_LIBRARY gives openssl.Mortmain
Worked for me on Fedora 21 with nss backend, thanks.Protagoras
like @EdwardNewell this fix didn't work for me on Scientific Linux (Rhel), although I did specify nss for PYCURL_SSL_LIBRARY, the backend remains (none/other)Fieldstone
This did not work for me on RHEL 6.7. The link-time backend was reported as "nss", and the compile-time backend as "(none/other)". What worked, was specifying --global-option="--with-nss" as pointed out in answer 1424462.Macaluso
On Mac I removed pycurl and installed with the flags: pip install --global-option="--with-openssl" --global-option=build_ext --global-option="-L/usr/local/opt/openssl/lib" --global-option="-I/usr/local/opt/openssl/include" pycurlDemurrer
This worked but only with the following options: pip install pycurl --compile --no-cache-dir on CentOS 7.3.Turtleback
O
59

With macOS 10.13, a brew-installed openSSL, and virtualenv, I was successful with:

# cd to your virtualenv, then…
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
Outdistance answered 15/9, 2017 at 13:24 Comment(7)
Yes, on MacOS 10.13.1 (High Sierra), that made the trick! Many thanks! In order to re-install openssl: brew reinstall opensslVivisection
Fixed the issue on Mac OSX 10.13.4! Thank you.Elkin
Thank you! Also fixed my issue. Mac OSX 10.13.4Tektite
Running pip with these parameters worked for me without installing openssl and keeping libressl: pip install pycurl --global-option="build_ext" --global-option="-I/usr/local/opt/openssl/include"Epitaph
After trying Michael Wilson's commands, I tried import pycurl and got: ImportError: pycurl: libcurl link-time ssl backend (none/other) is different from compile-time ssl backend (openssl)Shadchan
And I got the same ImportError: pycurl: libcurl link-time ssl backend (none/other) is different from compile-time ssl backend (openssl) after trying Kerim Gökarslan's pip install command above.Shadchan
Daryl sorry to hear that! It worked again for me on Mojave, so I'm not sure what's up.Outdistance
C
25

With pip 7.1 you can put the following in your requirements file:

pycurl==7.19.5.1 --global-option="--with-nss"

Simply replace nss with the relevant ssl backend library.

Cormorant answered 9/7, 2015 at 22:19 Comment(3)
This solution is better than exporting a var and reinstalling because it can be shared in the requirements.txt file and doesn't have to be repeated per-user.Walkup
export didn't work for me on CentOS 7. But setting the global option did. Thanks!Liaison
I had to combine your solution and that of @Michael Wilson to make it work on macOS. Looks like a crypto issue - some discussion here: github.com/pyca/cryptography/issues/3489Marikomaril
F
20

The method to fix the pycurl after Mac OS High Sierra update:

  1. Reinstall the curl libraries to use OpenSSL instead of SecureTransport

    brew install curl --with-openssl
    
  2. Install pycurl with correct build-time environment and paths

    export PYCURL_SSL_LIBRARY=openssl
    pip uninstall pycurl 
    pip install --no-cache-dir --global-option=build_ext --global-option="-L/usr/local/opt/openssl/lib" --global-option="-I/usr/local/opt/openssl/include" --user pycurl
    
Foxtrot answered 4/1, 2018 at 9:32 Comment(7)
Worked for me on High Sierra (using a virtualenv).Janeyjangle
Yes! Also see this article cscheng.info/2018/01/26/…Cloy
Worked for me on High Sierra (using a virtualenv) but I had to remove the --user flagRufescent
Thank you very much!! That was incredibly helpful. Running High Sierra and spending a couple of hours on it, this is the only solution which worked :)Interbrain
When I used the --user flag as above, I got: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.Shadchan
After doing the above without --user, it seemed to successfully install. But when I do an import pycurl I get: ImportError: pycurl: libcurl link-time ssl backend (none/other) is different from compile-time ssl backend (openssl)Shadchan
I finally found something that works. I created an answer below.Shadchan
F
19

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
Fireresistant answered 25/2, 2014 at 2:4 Comment(4)
The easy_install option was the only one that worked. I don't understand why this is so complicated. I needed export PYCURL_SSL_LIBRARY=openssl. My one reported "none/other" for the compiled library.Galata
Just ran into this problem and this solution was the only one that worked for me.Bewilder
In my experience, pip does not completely remove old version of pucurl that was installed with the OS (Centos7.2 in my case). Pip did not touch /usr/lib64/python2.7/site-packages/pycurl.so and egg-info files from the earlier version. Easy_install on the other hand, wiped those out in addition to placing pycurl egg into site-packages.Nuncle
Ugh, tried all the above and it didn't work. This worked for me when my original error message was ``` ImportError: pycurl: libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other)```Stallings
H
10

I had this problem for days. Finally with the help of other answers here (mainly Alexander Tyapkov's) I got it working for AWS Elastic Beanstalk.

Manual install (connecting with SSH):

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

IMPORTANT: Please note that you have to make sure you are using the currect version of Python and PIP, otherwise you might be compiling it for Python 2.x and using v3.x.

Auto-install in Elastic Beanstalk:

files:
  "/usr/local/share/pycurl-7.43.0.tar.gz" :
    mode: "000644"
    owner: root
    group: root
    source: https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz

commands:
  01_download_pip3:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    command: 'curl -O https://bootstrap.pypa.io/get-pip.py'
  02_install_pip3:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    command: 'python3 get-pip.py'
  03_pycurl_uninstall:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    command: '/usr/bin/yes | sudo pip uninstall pycurl'
  04_pycurl_download:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    command: 'curl -O https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz'
  05_pycurl_reinstall:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    command: 'sudo pip install pycurl-7.43.0.tar.gz --global-option="--with-nss"'

container_commands:
  09_pycurl_reinstall:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    # the upgrade option is because it will run after PIP installs the requirements.txt file.
    # and it needs to be done with the virtual-env activated
    command: 'source /opt/python/run/venv/bin/activate && pip3 install /usr/local/share/pycurl-7.43.0.tar.gz --global-option="--with-nss" --upgrade'

I had this problem because I was trying to configure Celery 4 with Django 1.10 in Elastic Beanstalk. If that's your case, I wrote a full blog post about it.

Hangnail answered 5/1, 2017 at 15:20 Comment(2)
ugh thank you. this stuff can be annoying, especially because eb config files seem very fickle and never give you reasonable errors (including formatting problems)Trafficator
I upvoted this answer as it helped me a lot to solve a similar problem when installing pycurl on AWS: #51020122Corinecorinna
L
8

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.

2019 Edit: Doing a sudo pip install might cause a problem with the machine's system install of Python. Perhaps try working in a Python virtual environment and install the packages there. If that doesn't work, the sudo trick in my answer is probably one of the last options to consider.

Laurentia answered 30/6, 2015 at 14:49 Comment(0)
F
5

You can download the tar.gz file from here. Then extract it into a folder. You'll find a setup.py file there. Run the command over there that the site mentioned. For example:

python setup.py --with-[ssl|gnutls|nss] install

FYI: I tried to install pycurl at my windows, but I couldn't. But did it on my linux.

Finochio answered 13/1, 2014 at 18:21 Comment(2)
thanks for the response, but this could only work for me if Im not doing the installation through a virtualenv and pipEducable
@Sabuj to install pycurl on Windows use one of the installers provided on this excellent website: lfd.uci.edu/~gohlke/pythonlibs/#pycurlBesought
T
5

I am running this on OS X and some of the above solutions weren't working. Similar to Edward Newell's comment the PYCURL_SSL_LIBRARY variable seemed to have been completely ignored.
Further reading of the PycURL installation doc revealed the following:

pip may reinstall the package it has previously compiled instead of recompiling pycurl with newly specified options

Therefore, I had to force it to compile with:

pip install --compile pycurl

That works on a number of cases. However, I did run into a few systems that continued to ignore the variable so, similar to maharg101's answer, I resorted to the install options which through pip can be set like this:

pip install pycurl --global-option="--with-[ssl|gnutls|nss]"

where you select one of the three options inside the square brackets. Notice that the available option is ssl and not openssl. If you specify --with-openssl you'll get an error. Also note that if you were messing around with the PYCURL_SSL_LIBRARY variable and switching it to funky values to see what would happen this last command will definitely catch it and throw an error if the value is set but not valid.

Timisoara answered 14/11, 2015 at 17:59 Comment(2)
uninstall pycurl first, and do pip install pycurl --global-option="--with-nss" works for me. For the record, my error is ImportError: pycurl: libcurl link-time ssl backend (nss) is different from compile-time ssl backend (openssl)Tannic
Thanks @Tannic the global option trick worked for me, even though I tried in while installing from tar, it worked with pip but not with setup.py weird...Fieldstone
I
5

For anyone having problem inside PyCharm CE on macOS Mojave this is how i got it working in venv:

  • specify version: 7.43.0.1
  • Options: --install-option=--with-openssl --install-option=--openssl-dir=/usr/local/opt/openssl

PyCharm Project Interpreter screen shot

Infecund answered 19/1, 2019 at 16:35 Comment(1)
For me on macOS Mojave I needed to run brew reinstall openssl and then pip install pycurl==7.43.0.1 --install-option=--with-openssl --install-option=--openssl-dir=/usr/local/opt/opensslRufescent
T
4

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'

Topminnow answered 21/12, 2016 at 0:5 Comment(0)
S
3

I tried everything here on macOS 10.13 with no success. Then I found https://gist.github.com/webinista/b4b6a4cf8f158431b2c5134630c2cbfe which worked:

brew install curl --with-openssl
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

This worked for me both when not using a virtualenv and within a virtualenv.

Shadchan answered 18/1, 2019 at 18:2 Comment(0)
N
2

This worked for me:

pip install --compile --install-option="--with-openssl" pycurl

Nasalize answered 28/7, 2018 at 15:29 Comment(0)
L
1

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
Lohse answered 12/8, 2016 at 18:38 Comment(1)
Same here, on CentOS 7 it wasn't working until I added the --no-cahe-dir option. Just want to further mention that it only succeeded running under root with su - as @Laurentia suggested. Doing sudo pip3 ... wasn't good enough. Probably necessary for the environment variable to be picked up.Dulci
S
1

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
Sension answered 16/11, 2017 at 18:44 Comment(1)
This worked for me as well on Python 2.7.10 on High Sierra.Shelves
G
1

After being stuck on this for a long time, I found out that apple stopped including OpenSSL headers since OS X 10.11 El Capitan. how to fix?

1) brew install openssl

2) echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile (or .zshrc for zsh, etc)

3) pip uninstall pycurl

4) pip install --install-option="--with-openssl" --install-option="--openssl-dir=/usr/local/opt/openssl" pycurl
Gantry answered 30/1, 2018 at 7:50 Comment(1)
Sure thing, took me a lot of time to make it work, pretty annoying I must say. Have fun!!Gantry
B
1

Same problem on amazonlinux - solved
I had this problem while creating a docker image based on amazonlinux, installing python3.7 and adding the pycurl module. All other python modules were installed correctly except pycurl. After trying many of the solutions proposed in the threads linked to this problem I finally solved my problem by using following commands for installation of all the pieces.
yum -y install python3 python3-devel gcc libcurl-devel aws-cli openssl-static.x86_64
then installed other modules like psycopg2-binary, requests, certifi using:
pip3 install --user --no-cache-dir -r requirements.txt

and finally installed pycurl module using:

pip3 install --user --global-option="--with-openssl" --no-cache-dir pycurl
and passing here the openssl global option. The installation of the static library openssl-static.x86_64 solved the problem in my case as using global option used by the second pip3 command.

Bonefish answered 1/10, 2019 at 22:24 Comment(0)
H
0

For python 2.7

sudo apt-get install build-essential libssl-dev libffi-dev python-dev

For python 3.5 also install the next:

sudo apt-get install python3.5-dev

Download the latest pycurl-7.43.0.tar.gz (md5) Source from pypi https://pypi.python.org/pypi/pycurl/7.43.0#downloads and run the next command:

python setup.py --with-openssl install

Also you can do it into python environment:

(test_env)user@pc:~/Downloads/pycurl-7.43.0$ python setup.py --with-openssl install
Herwin answered 24/9, 2016 at 13:47 Comment(0)
H
0
pip install -U pip

if [ "$(curl --version | grep NSS 2>/dev/null)" ]; then
    pip install --compile --install-option="--with-nss" pycurl
else
    pip install --compile --install-option="--with-openssl" pycurl
fi
Hopeless answered 28/12, 2016 at 12:46 Comment(0)
M
0

I encountered this problem and Sanket Jagtap's answer worked for me. I tried the answer with the most votes answer but it did not work.

My openssl old version is 1.0.1t, I think reinstalling openssl may solve this problem.

--- pycurl's openssl backend time....

I rebuilt the latest openssl and tried this answer. Check this out.

pip install --compile --install-option="--with-openssl" pycurl

This worked for me.

i recommend we should reinstall our openssl for try..

Mclean answered 22/4, 2017 at 3:16 Comment(0)
S
0

Following worked for me with Python3.6

MacOS High-Sierra

sudo pip3 uninstall pycurl
sudo pip3 install --compile --install-option="--with-openssl" pycurl 

CentOS 7

sudo pip3 uninstall pycurl
sudo pip3 install --compile --install-option="--with-nss" pycurl
Speakeasy answered 10/1, 2018 at 12:47 Comment(0)
P
0

This link sums up the reason why the errors occur and gives a clear instruction to fix the problem.

https://cscheng.info/2018/01/26/installing-pycurl-on-macos-high-sierra.html

For me, the problem occurred when I upgraded to High-Sierra from El Captain.

Posology answered 19/3, 2018 at 3:20 Comment(0)
H
0

FWIW, I ran into a lot of issues getting this working via AWS Elastic Beanstalk and finally was able to get it working with:

packages:
  yum:
    openssl-devel: []
    libcurl-devel: []

container_commands:
  # Reinstall PyCurl with correct ssl backend
  05_reinstall_pycurl:
    command: |
      pip install --upgrade pip
      pip uninstall -y pycurl
      pip install --global-option='--with-openssl' pycurl
Humorous answered 22/1, 2020 at 23:44 Comment(0)
E
0

Recently while upgrading a Django project I had the similar error. But this time setting the environment variable did not work. So I had to set both environment variable export PYCURL_SSL_LIBRARY=openssl and pass the flag --global-option="with-openssl".

The original answer was posted on this page

Educable answered 31/7, 2020 at 11:55 Comment(0)
F
-1
export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib

pip install pycurl --global-option="--with-openssl"
Frankpledge answered 29/6, 2018 at 6:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.