24

I wanted to run python file. But I could check this error when I ran it.

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

My system is Mac os 10.13.2 and I used python 2.7

Thomas
  • 241
  • 1
  • 2
  • 3

8 Answers8

37

Looks like something went wrong with pycurl/openssl, try this:

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

if still fails, try this as well

brew reinstall openssl
Eytan Avisror
  • 2,860
  • 19
  • 26
  • Thank you for your kindness!! FInally I could make it! – Thomas Dec 19 '17 at 14:19
  • running `brew reinstall openssl` was required on an upgraded macOS 10.13 machine – Patrick Dec 27 '17 at 19:08
  • 1
    how the heck did you know this solution (compile with ssl)? Thx! – jsfa11 Feb 11 '21 at 14:05
  • 4
    +1, thanks. Anyone have any idea how I can install with poetry? `poetry add pycurl` doesn't seem to give the option of supplying flags. – P i Jun 28 '21 at 16:07
  • 1
    On a macOS 12.3, after `brew reinstall openssl` you can run `brew info openssl` and it will tell you some environment variables you need to set for the pycurl install to work. – Noumenon Apr 04 '22 at 16:54
  • 1
    I had to find the path to openssl via `brew info openssl` and pass it to pip: `pip install --compile --install-option="--with-openssl" --install-option="--openssl-dir=/opt/homebrew/opt/openssl@3/" pycurl` – Falko Jun 21 '22 at 14:54
15

This was done by my fellow mac users.

# pycurl
pip uninstall pycurl
export CPPFLAGS=-I/usr/local/opt/openssl/include # may be needed
export LDFLAGS=-L/usr/local/opt/openssl/lib # may be needed
pip install --no-cache-dir --compile --ignore-installed --install-option="--with-openssl" pycurl

I got this same issue in windows which had a different fix(perhaps this might fit Mac too). In my requirements.txt I had pycurl-7.43.0.4 but on the windows dowloader page I could only find 7.44.1 which I installed (pip install .\pycurl-7.44.1-cp37-cp37m-win_amd64.whl). And then on starting my Django server python manage.py runserver I got the error in question. And the solution was to bring the pycurl back to it's expected version. pip install pycurl==7.43.0.5 and it replaced the version as given below. And the error was gone! enter image description here

Blue Clouds
  • 7,295
  • 4
  • 71
  • 112
8

For m1 users, it works for me

brew install curl-openssl
pip uninstall pycurl

PYCURL_SSL_LIBRARY=openssl \
    LDFLAGS="-L$(brew --prefix openssl)/lib" \
    CPPFLAGS="-I$(brew --prefix openssl)/include" 

pip install --compile --install-option="--with-openssl" pycurl
Jacob kshin
  • 81
  • 1
  • 1
  • 1
    I had to add `--use-pep517` in addition: ```pip install --no-cache-dir --ignore-installed --compile --install-option="--with-openssl" pycurl --use-pep517``` – bvoq Nov 07 '22 at 16:34
  • `--install-option` is not an option for later versions of pip – Jeremy Jul 06 '23 at 17:02
5

How I resolve this issue on my Mac Book Pro M1 (Chip Apple M1 Pro).

I am using system provided Python 3.9.6 as MacOs Monterey 12.6 completely removed Python 2.7 and providing Python 3.9.6 as system Python.

two thing is very important to know curl info by using

  1. curl-config --features
  2. brew openssl info

this gives you information according to your own machine setup for using in below installation to use.

In my case it was

export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"

For pkg-config to find openssl@3 you may need to set:

export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"
pip install --no-cache-dir --compile --ignore-installed --install-option="--with-openssl" pycurl

it was done!!! perfectly.

Alternatively, if you get an error saying

no such option: --install-option

You can try:

env PYCURL_SSL_LIBRARY=openssl LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib" CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include" pip install --no-cache-dir --compile --ignore-installed pycurl

and it should work!

Asif Khan
  • 91
  • 1
  • 6
3

Setup: MacOS Ventura, M1, Python 3.9, pip 23.1.2

With pip 23.1, --install-option="..." is deprecated.

What worked for me was actually following the installation guide from pycurl: http://pycurl.io/docs/latest/install.html#easy-install-pip

pip3 uninstall pycurl  
brew install curl-openssl
export PYCURL_SSL_LIBRARY=openssl
pip3 install --no-cache-dir --ignore-installed --compile pycurl
timreibe
  • 31
  • 1
2

Reinstall the curl libraries

brew install curl --with-openssl

Install pycurl with correct 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"  pycurl
Ruslan
  • 316
  • 1
  • 3
  • 16
0

On macOS Catalina (v10.15.6), make sure you uninstall previous curl then install curl-openssl as well as exporting variables so compiler can find them:

brew uninstall curl
brew install curl-openssl

export PYCURL_SSL_LIBRARY=openssl
export PYCURL_CURL_CONFIG=/usr/local/opt/curl-openssl/bin/curl-config;export LDFLAGS='-L/usr/local/opt/openssl/lib -L/usr/local/opt/c-ares/lib -L/usr/local/opt/nghttp2/lib -L/usr/local/opt/libmetalink/lib -L/usr/local/opt/rtmpdump/lib -L/usr/local/opt/libssh2/lib -L/usr/local/opt/openldap/lib -L/usr/local/opt/brotli/lib';export CPPFLAGS=-I/usr/local/opt/openssl/include;pip install pycurl --compile --no-cache-dir

pip install pycurl
Andre Pereira
  • 219
  • 6
  • 16
  • This works for me, but for my case, the install command requires one more flag: `ARCHFLAGS="-arch x86_64" pip install pycurl --compile --no-cache-dir` – Kir Chou Oct 24 '20 at 02:54
  • For me on BigSur (11.2.3) with a M1: `export PYCURL_SSL_LIBRARY=openssl export PYCURL_CURL_CONFIG=/opt/homebrew/opt/curl/bin/curl-config export LDFLAGS='-L/opt/homebrew/opt/openssl/lib/' export CPPFLAGS=-I/opt/homebrew/opt/openssl/include pip install pycurl --compile --no-cache-dir ` – Blitz Oct 05 '21 at 13:32
0

I am running MacOS Ventura on my MacBook Pro. We use Python 3.7. The following worked for me:

% python3.7 -m pip uninstall pycurl
% brew install curl
% brew install openssl

% export LDFLAGS="-L/usr/local/opt/curl/lib $LDFLAGS"
% export CPPFLAGS="-I/usr/local/opt/curl/include $CPPFLAGS"
% export PKG_CONFIG_PATH=/usr/local/opt/curl/lib/pkgconfig

% python3.7 -m pip install pycurl==7.45.2 --no-cache-dir --compile --ignore-installed --install-option="--openssl-dir=/usr/local/opt/openssl@3/"
dirtyqwerty
  • 185
  • 2
  • 16