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

1
  • 1
    What is your OS?
    – Evgenii
    Commented Jun 5, 2018 at 11:44

26 Answers 26

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
6
  • 2
    Thanks, PYCURL_SSL_LIBRARY=openssl works perfectly!
    – thnee
    Commented Jan 19, 2014 at 16:57
  • 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.
    – Serge
    Commented Jan 19, 2015 at 7:14
  • 13
    pip install pycurl --no-cache-dir Commented Mar 10, 2016 at 12:06
  • Thanks. I've looked through a number of potential solutions to this issue. This solution worked the first time. Commented Jun 18, 2018 at 9:09
  • step by step virtualenv install example yippeecode.com/view-code/343QWQT144/… Commented Feb 28, 2019 at 4:35
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
7
  • 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
    Commented Jun 7, 2014 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. Commented Mar 7, 2015 at 23:43
  • 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) Commented Oct 27, 2015 at 9:46
  • 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
    Commented Jan 3, 2018 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
    Commented Feb 6, 2018 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
7
  • 5
    Yes, on MacOS 10.13.1 (High Sierra), that made the trick! Many thanks! In order to re-install openssl: brew reinstall openssl Commented Nov 11, 2017 at 11:36
  • 1
    Fixed the issue on Mac OSX 10.13.4! Thank you. Commented Apr 5, 2018 at 10:43
  • 1
    Thank you! Also fixed my issue. Mac OSX 10.13.4
    – Kyias
    Commented May 8, 2018 at 8: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" Commented Nov 9, 2018 at 5:21
  • 2
    Daryl sorry to hear that! It worked again for me on Mojave, so I'm not sure what's up. Commented Jan 18, 2019 at 3: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.

3
  • 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
    Commented Mar 8, 2016 at 1:44
  • 1
    export didn't work for me on CentOS 7. But setting the global option did. Thanks! Commented Apr 27, 2017 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: github.com/pyca/cryptography/issues/3489
    – kip2
    Commented Jul 17, 2018 at 7: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
    
7
  • 2
    Worked for me on High Sierra (using a virtualenv).
    – djangoat
    Commented Mar 8, 2018 at 6:17
  • 1
    Yes! Also see this article cscheng.info/2018/01/26/… Commented Apr 13, 2018 at 0:23
  • Worked for me on High Sierra (using a virtualenv) but I had to remove the --user flag Commented Oct 11, 2018 at 10:41
  • 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 :)
    – Alessandro
    Commented Oct 12, 2018 at 10:56
  • 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. Commented Jan 17, 2019 at 23:49
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
4
  • 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. Commented May 10, 2016 at 15:30
  • Just ran into this problem and this solution was the only one that worked for me. Commented Jan 12, 2017 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
    Commented Dec 2, 2017 at 4: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)``` Commented Dec 13, 2017 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.

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)
    – Ian
    Commented Jul 28, 2017 at 20:19
  • I upvoted this answer as it helped me a lot to solve a similar problem when installing pycurl on AWS: stackoverflow.com/questions/51019622/…
    – Greg Holst
    Commented May 22, 2019 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.

0
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.

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

2
  • 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
    Commented Nov 16, 2015 at 8: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... Commented Dec 7, 2015 at 9: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

1
  • 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 Commented May 21, 2019 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'

0
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.

2

This worked for me:

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

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
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 @alfonso suggested. Doing sudo pip3 ... wasn't good enough. Probably necessary for the environment variable to be picked up.
    – Nagev
    Commented Oct 9, 2017 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
1
  • This worked for me as well on Python 2.7.10 on High Sierra.
    – skyler
    Commented Dec 29, 2017 at 0:58
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
1
  • Sure thing, took me a lot of time to make it work, pretty annoying I must say. Have fun!!
    – Whitebear
    Commented Feb 13, 2018 at 18:42
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.

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
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..

0
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
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.

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
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

-1
export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.