Skip to content

Instantly share code, notes, and snippets.

@enfont
Last active June 4, 2024 14:28
Show Gist options
  • Save enfont/70b87caca1a16fabb8c9e9e4e142f099 to your computer and use it in GitHub Desktop.
Save enfont/70b87caca1a16fabb8c9e9e4e142f099 to your computer and use it in GitHub Desktop.
Fixing Error: ImportError: pycurl: libcurl link-time version (7.79.1) is older than compile-time version (7.87.0)

Fixing Pycurl error on MacOs Monterrey

Issue:

celery -A workers worker --loglevel=INFO -c 2
...
  File "/Users/USERNAME/.pyenv/versions/3.8.5/envs/notifications38/lib/python3.8/site-packages/kombu/asynchronous/http/curl.py", line 41, in __init__
    raise ImportError('The curl client requires the pycurl library.')
ImportError: The curl client requires the pycurl library.

Derived from the import of pycurl:

❯ python3
Python 3.8.5 (default, Sep  3 2021, 09:13:17) 
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
>>> import pycurl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: pycurl: libcurl link-time version (7.79.1) is older than compile-time version (7.87.0)

Fixing the issue

  • Reinstalling both openssl and curl from brew to be sure we have the latest versions:
brew uninstall openssl
brew uninstall curl
brew install openssl
brew install curl

Check the paths of the libraries so you can properly set LDFLAGS and CPPFLAGS
  • Reinstall pycurl
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=openssl                                                                                                                                                                                                                                                х INT Py notifications38 3.8.5
export LDFLAGS="-L/usr/local/opt/curl/lib"
export CPPFLAGS="-I/usr/local/opt/curl/include"
pip install pycurl --config-settings="--build-option=--with-openssl" --config-settings="build-option=--openssl-dir=/usr/local/opt/openssl" --no-binary :all: --no-cache-dir
# For older version of pip <23.1
# pip install --verbose --no-cache-dir --compile --ignore-installed --install-option="--with-openssl" --install-option="--openssl-dir=/usr/local/opt/openssl@1.1" pycurl
  • Check if the error still persists:
python3
import pycurl
  • If the error still persists, check with otool what linked curl library has the installed python library:
❯ otool -L /Users/USERNAME/.pyenv/versions/3.8.5/envs/notifications38/lib/python3.8/site-packages/pycurl.cpython-38-darwin.so
/Users/USERNAME/.pyenv/versions/3.8.5/envs/notifications38/lib/python3.8/site-packages/pycurl.cpython-38-darwin.so:
	/usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib (compatibility version 1.1.0, current version 1.1.0)
	/usr/local/opt/openssl@1.1/lib/libcrypto.1.1.dylib (compatibility version 1.1.0, current version 1.1.0)
	/usr/lib/libcurl.4.dylib (compatibility version 7.0.0, current version 9.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)

If the library is the system one, /usr/lib/libcurl.4.dylib, just swap it to the proper one:

❯ install_name_tool -change /usr/lib/libcurl.4.dylib /usr/local/opt/curl/lib/libcurl.4.dylib /Users/USERNAME/.pyenv/versions/3.8.5/envs/notifications38/lib/python3.8/site-packages/pycurl.cpython-38-darwin.so

❯ otool -L /Users/USERNAME/.pyenv/versions/3.8.5/envs/notifications38/lib/python3.8/site-packages/pycurl.cpython-38-darwin.so
/Users/USERNAME/.pyenv/versions/3.8.5/envs/notifications38/lib/python3.8/site-packages/pycurl.cpython-38-darwin.so:
	/usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib (compatibility version 1.1.0, current version 1.1.0)
	/usr/local/opt/openssl@1.1/lib/libcrypto.1.1.dylib (compatibility version 1.1.0, current version 1.1.0)
	/usr/local/opt/curl/lib/libcurl.4.dylib (compatibility version 7.0.0, current version 9.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment