LaptopScreenWithGlasses

How to (Finally) Install PyCURL on MacOS

April 24, 2023

Oren Cohen

In this guide, I show you a complete solution on how to install pycurl on macOS.

Every few months, as part of one project or another, I find myself installing pycurl on my Macbook and experiencing installation failures. As a Backend Engineer at Edgybees, I have many projects that require pycurl to operate correctly. The backend infrastructure at Edgybees consists of many small but effective microservices that sometimes need to talk to each other. Pycurl is one tool that allows Edgybees services to facilitate that communication using inter-cluster requests.

I used to spend a lot of time googling what was wrong with my installation and how to fix it. Not all solutions worked. There were some that were outright erroneous. Those that did work did not explain the source of their answer well enough. And now, finally, I found the source of all those Stack Overflow half-answers: Brew.

How to Install Brew on Mac

Brew is a package manager for MacOS computers. According to brew’s official website, you need to run this command to install brew:

`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`

How to Install Pycurl on MacOS

Step 1: open a terminal and run brew info openssl

If OpenSSL is not installed, start with brew install openssl before retrying the above command.

If you’re using MacOS Ventura like me, you should see output similar to this in your terminal. It will still be similar even if you’re using an earlier version.

Step 2: export env variables as suggested.

Export the suggested compilations environment variables in the same terminal where you attempt to install pycurl (works in your poetry shell, too, for those who use that package manager). This includes the update to your PATH and the compiler flags.

The reason is that the LDFLAGS and CPPFLAGS env variables are not automatically set on the system because macOS automatically provides LibreSSL. And in addition, the PATH doesn’t include it either in favor of LibreSSL. Hence, pycurl fails to find OpenSSL when trying to install it.

And that’s it! Your pycurl installation should work as expected.

Conclusion

Working on Edgybees’ backend services, I install a lot of tools on a daily basis. Installing pycurl on Mac requires some info from brew about your OpenSSL installation. Once you export the required env variables, you should be able to install pycurl with no problems on your macOS.

Facebook
Twitter
LinkedIn

Related posts