Building from source on MacOS

I’m coming back to MacOS have several years away visiting Linux (damn you, Touch Bar!)… I find I’ve forgotten just about everything special about building on that platform. The usual

./configure && make -j && make test

works, but fails to build or test a number of modules, most notably for me at the moment, _ssl and _tkinter. I installed openssl via Homebrew and configured --with-openssl=/opt/homebrew but building Modules/_ssl.o fails:

In file included from Modules/_ssl.c:31:
Modules/_ssl.h:5:10: fatal error: 'openssl/evp.h' file not found
#include "openssl/evp.h"

evp.h is in an unusual place:

% find /opt/homebrew -name 'evp.h'           

I’m certainly missing something basic. I’ve forgotten everything I ever knew about Homebrew. brew search didn’t turn up any sort of openssl-dev package as I’d expect on Linux when I needed to compile something. Do I need to manually craft a bunch of *FLAGS environment variables to tell configure & make where stuff is?

More generally, is there a How-To for building on MacOS?

I assume you are building python becuase you want to work on its code or use 3.12 etc.

Since you are using homebrew you could find the script that they used to build python.

Since openssl/evp.h is not found the problem is likely that the wrong -I is pass to the compiler. I would check the output of configure to see what it reported for openssl and also check the -I in the Makefile.

Answering your more general question, there are instructions for macOS in the dev guide here: Setup and Building
There’s also the mac readme cpython/README.rst at main · python/cpython · GitHub

The command seem correct to me (although I didn’t verify the exact commands because of idiosyncrasies in my dev setup)

1 Like

Thanks. I don’t really need/want a framework build, just a normal old build referencing various other libraries. It seems odd to me that the OpenSSL library and include files wouldn’t be symlinked from /opt/homebrew/lib or /opt/homebrew/include.

(… a day or so passes, after which we check back in with the problem …)

After a bit of horsing around, I figured out that in addition to installing both tcl-tk and openssl@3 packages, I needed to create symlinks for pkg-config (in /opt/homebrew/lib/pkgconfig). After that, Python’s configure script was able to suss out everything it needed to build modules using both libraries.

(Apologies for the premature send — fat fingered things…)

That’s what’s described in the dev guide link (the first link) Shantanu posted; just a normal old build.

Yes, normal old build, but nothing about installing/accessing third party packages which might or might not be installed on the Mac. That was my dilemma, not being able to run SSL- or Tk-related tests. I eventually figured out how to do that with an extra step in homebrew of creating the necessary pkgconfig symlinks manually.

If there’s something missing, please file an issue about it so we can improve the dev guide.

There is already a line in the dev guide that reads brew install pkg-config openssl@1.1 xz gdbm tcl-tk. Does that cover the third party packages you were missing? If not, can you tell us which pacakges were missing?

Yes, that’s part of it, and I missed it. My apologies. However, Homebrew doesn’t automatically make some packages “findable”, at least if they are provided in some other form by Apple. The result is that the user has to go to /opt/homebrew/lib/pkgconfig and manually create symlinks for the relevant *.pc files.

Edit: I assume these sort of details probably vary by MacOS version. I happen to have just upgraded to Ventura (and have only had this machine for a month or two).

1 Like