Reputation: 23
Whenever I start celery worker in my django project, it fails to start with the following error:
"Unrecoverable error: ImportError('The curl client requires the pycurl library.')
I have visited all the github issues and questions posted on stackoverflow but unable to pinpoint this issue. My pycurl installation is done successfully and if I run python -c 'import pycurl' && echo "Success"
. It returns me success but whenever I run celery worker it still gives me the pycurl error.
I was expecting celery to run successfully but in return I get an import error.
If I go to the kombu package which is installed and try to print traceback value then it outputs:
pycurl: libcurl link-time version (7.76.1) is older than compile-time version (7.86.0)
brew info openssl output is as follow:
openssl@3 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.
If you need to have openssl@3 first in your PATH, run:
echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> /Users/<>/.bash_profile
For compilers to find openssl@3 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@3/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@3/include"
For pkg-config to find openssl@3 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@3/lib/pkgconfig"
brew info curl output is as follows:
curl is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have curl first in your PATH, run:
echo 'export PATH="/usr/local/opt/curl/bin:$PATH"' >> /Users/<>/.bash_profile
For compilers to find curl you may need to set:
export LDFLAGS="-L/usr/local/opt/curl/lib"
export CPPFLAGS="-I/usr/local/opt/curl/include"
For pkg-config to find curl you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/curl/lib/pkgconfig"
Upvotes: 0
Views: 656
Reputation: 111
I encountered this issue on a Mac Pro (intel) running Ventura 13.0. Seems like many others have had mixed results fixing the problem given the number of posts on SO and other sites. This worked for me but your mileage may vary.
This approach ensures the pycurl version matches the macOS version of curl. Other approaches try to install curl from homebrew and link against that. The homebrew approach seems to work for python but Django and celery always linked against the built in curl.
The Problem
➜ ~ pip install pycurl
Collecting pycurl
Using cached pycurl-7.45.2-cp310-cp310-macosx_13_0_x86_64.whl
Installing collected packages: pycurl
Successfully installed pycurl-7.45.2
➜ ~ python
Python 3.10.11 (main, Apr 7 2023, 07:31:31) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycurl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: pycurl: libcurl link-time version (7.84.0) is older than compile-time version (7.87.0)
Note the link time version libcurl link-time version (7.84.0)
. Yours may be different.
The Solution
Build pycurl against same source as the installed version.
# Remove installed pycurl version
pip uninstall -y pycurl
# Remove homebrew curl
brew uninstall curl
# Use the same version of curl as the error message
export CURL_VERSION=7.84.0
# Install openssl for pycurl compiling
brew install openssl || brew update openssl
# Downloading sources
curl --silent "https://curl.se/download/curl-${CURL_VERSION}.tar.bz2" > "curl-${CURL_VERSION}.tar.bz2"
tar -xf "curl-${CURL_VERSION}.tar.bz2"
# Explicitly indicate openssl
export PYCURL_SSL_LIBRARY=openssl
# Setting up compiler flags and PATH
export PATH="$(pwd)/curl-${CURL_VERSION}/bin:$PATH"
export LDFLAGS="-L$(pwd)/curl-${CURL_VERSION}/lib -L/usr/local/opt/openssl@3/lib"
export CPPFLAGS="-I$(pwd)/curl-${CURL_VERSION}/include -I/usr/local/opt/openssl@3/include"
# Installing
pip install --no-cache-dir --compile pycurl
# Checking up
python -c 'import pycurl' && echo 'Success!'
You can find some great conversation on the issue here: https://gist.github.com/vidakDK/de86d751751b355ed3b26d69ecdbdb99
Upvotes: 0