I know this question has been asked before am I have tried most of the solutions and still having issues. So, I am on Mac OS Monterey (12.6.1). Installed Python 3.7.12 (using pyenv). Using Poetry for dependency management. I did the below steps after activating & deactivating the virtual environment using poetry (source $(poetry env info --path)/bin/activate
)
- Removed existing pycurl using brew
- Installed openssl (
brew install openssl
) - Verified ssl installation directory
brew --prefix openssl
/opt/homebrew/opt/openssl@3
$ ls -la /usr/local/opt/openssl@3
lrwxr-xr-x 1 xxxxxx admin 25 14 Dec 22:57 /opt/homebrew/opt/openssl@3 -> ../Cellar/openssl@3/3.0.7
- Install PyCurl specifying inline the above
openssl
install directories like this
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 pycurl
PyCurl installs without any problem but when I try to import pyCurl I get the following error message.
Python 3.7.12 (default, Dec 14 2022, 22:00:27)
[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.79.1) is older than compile-time version (7.86.0)
>>> quit()
PS:
poetry env info --path
does return the correct poetry virtual env path.I tried switching my Python version to 3.8.X and 3.9.X and still having the same issue.
I also updated my curl version to 7.86 using brew and doing a
brew --version
does conform the same.
$ curl --version ✔ at 11:13:19 pm ▓▒░
curl 7.86.0 (aarch64-apple-darwin21.6.0) libcurl/7.86.0 (SecureTransport) OpenSSL/1.1.1s zlib/1.2.11 brotli/1.0.9 zstd/1.5.2 libidn2/2.3.4 libssh2/1.10.0 nghttp2/1.51.0 librtmp/2.3
Release-Date: 2022-10-26
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd
What am I missing from the above steps? Thank you in advance for your time... :)
CodePudding user response:
After a lot of trial and errors I managed to find a way around this. The easiest way for me was to download curl and manually set the path for PyCurl compilation. Following were the steps I did to resolve my issue
$> pip uninstall pycurl
$> brew uninstall curl
# Install openssl to compile pycurl
$> brew install openssl@3
# If you already have openssl@3 installed run the following
# command and note the path of LDFLAGS an CPPFLAGS
$> brew info openssl@3
# Downloading latest version of Pycurl
# I downloaded curl to my HOME path
$> wget https://curl.haxx.se/download/curl-7.86.0.tar.bz2
# Unzip
$> tar -xf curl-7.86.0.tar.bz2
#Add the following to .zshrc
export PATH="$(HOME)/curl-7.86.0/bin:$PATH"
export LDFLAGS="-L$HOME/curl-7.86.0/lib -L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I$HOME/curl-7.86.0/include -I/opt/homebrew/opt/openssl@3/include"
# Install PyCurl
$> pip install --no-cache-dir --compile --install-option="--with-openssl" pycurl
#Checking if the installation went right
$> python -c "import pycurl"
Since I was using Poetry the above steps did not add PyCurl to my virtual env. I went into my project, activated my virtual env (source $(poetry env info --path)/bin/activate
) and then ran pip install --no-cache-dir --compile --install-option="--with-openssl" pycurl
Hope this helps !!!.