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

jww
  • 97,681
  • 90
  • 411
  • 885
helloworld2013
  • 3,094
  • 5
  • 19
  • 26

26 Answers26

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
Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
helloworld2013
  • 3,094
  • 5
  • 19
  • 26
78

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
georgexsh
  • 15,984
  • 2
  • 37
  • 62
DrStrangepork
  • 2,955
  • 2
  • 27
  • 33
  • 1
    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 . – Nishant Jun 07 '14 at 19:47
  • 6
    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`. – Edward Newell Mar 07 '15 at 23:43
  • Worked for me on Fedora 21 with nss backend, thanks. – therealrootuser Apr 28 '15 at 21:23
  • 1
    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) – Yondaime008 Oct 27 '15 at 09:46
  • 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](http://stackoverflow.com/a/31329250/1424462). – Andreas Maier May 31 '16 at 08:24
  • 3
    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" pycurl` – eigenein Jan 03 '18 at 11:39
  • 2
    This worked but only with the following options: `pip install pycurl --compile --no-cache-dir` on CentOS 7.3. – Robert Yi Feb 06 '18 at 14:42
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
Community
  • 1
  • 1
Michael Wilson
  • 800
  • 8
  • 15
  • 5
    Yes, on MacOS 10.13.1 (High Sierra), that made the trick! Many thanks! In order to re-install openssl: ``brew reinstall openssl`` – Denis Arnaud Nov 11 '17 at 11:36
  • 1
    Fixed the issue on Mac OSX 10.13.4! Thank you. – user1192748 Apr 05 '18 at 10:43
  • 1
    Thank you! Also fixed my issue. Mac OSX 10.13.4 – Kyias May 08 '18 at 08:30
  • 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"` – Kerim Gökarslan Nov 09 '18 at 05:21
  • 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)` – Daryl Spitzer Jan 17 '19 at 23:16
  • 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. – Daryl Spitzer Jan 17 '19 at 23:18
  • 2
    Daryl sorry to hear that! It worked again for me on Mojave, so I'm not sure what's up. – Michael Wilson Jan 18 '19 at 03:15
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.

maharg101
  • 507
  • 4
  • 6
  • 1
    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. – dfarrell07 Mar 08 '16 at 01:44
  • 1
    export didn't work for me on CentOS 7. But setting the global option did. Thanks! – Aaron Nguyen Apr 27 '17 at 23:58
  • 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: https://github.com/pyca/cryptography/issues/3489 – kip2 Jul 17 '18 at 07:57
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
    
pallly
  • 629
  • 5
  • 13
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
Joel Bondurant
  • 841
  • 1
  • 10
  • 17
  • 1
    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. – CMCDragonkai May 10 '16 at 15:30
  • Just ran into this problem and this solution was the only one that worked for me. – Boudewijn Aasman Jan 12 '17 at 21:59
  • 2
    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. – sokhaty Dec 02 '17 at 04:04
  • 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)``` – James McCormac Dec 13 '17 at 11:47
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.

Diego Jancic
  • 7,280
  • 7
  • 52
  • 80
  • 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) – Ian Jul 28 '17 at 20:19
  • I upvoted this answer as it helped me a lot to solve a similar problem when installing pycurl on AWS: https://stackoverflow.com/questions/51019622/curl-is-configured-to-use-ssl-but-we-have-not-been-able-to-determine-which-ssl/56260434#56260434 – Greg Holst May 22 '19 at 15:40
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.

alfonso
  • 884
  • 17
  • 31
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.

Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85
  • thanks for the response, but this could only work for me if Im not doing the installation through a virtualenv and pip – helloworld2013 Jan 13 '14 at 18:57
  • @Sabuj to install _pycurl_ on Windows use one of the installers provided on this excellent website: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycurl – Adam Apr 25 '14 at 14:19
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.

Community
  • 1
  • 1
Gunga
  • 84
  • 2
  • 1
  • 1
    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)` – ahyong Nov 16 '15 at 08:29
  • Thanks @ahyong 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... – Yondaime008 Dec 07 '15 at 09:44
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

fabe
  • 466
  • 5
  • 6
  • 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/openssl – user495732 Why Me May 21 '19 at 13:11
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'

Alexander Tyapkov
  • 4,837
  • 5
  • 39
  • 65
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.

Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
2

This worked for me:

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

David Rogers
  • 2,601
  • 4
  • 39
  • 84
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
Robert Kelly
  • 996
  • 1
  • 10
  • 19
  • 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 @alfonso suggested. Doing `sudo pip3 ...` wasn't good enough. Probably necessary for the environment variable to be picked up. – Nagev Oct 09 '17 at 14:05
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
Machavity
  • 30,841
  • 27
  • 92
  • 100
vairav
  • 19
  • 1
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
Whitebear
  • 1,761
  • 2
  • 12
  • 22
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.

rimetnac
  • 134
  • 2
  • 11
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
Andrew Nodermann
  • 610
  • 8
  • 13
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
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..

Community
  • 1
  • 1
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
Samuel
  • 3,631
  • 5
  • 37
  • 71
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.

hyukkyulee
  • 1,024
  • 1
  • 12
  • 17
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
Sean Chon
  • 397
  • 5
  • 13
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

helloworld2013
  • 3,094
  • 5
  • 19
  • 26
-1
export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib

pip install pycurl --global-option="--with-openssl"
Evgenii
  • 3,283
  • 3
  • 27
  • 32