Fixing python-build on macOS High Sierra

Posted in Category • September 27, 2017

I upgraded to macOS High Sierra yesterday. The most expected feature is APFS, I’m so excited about it that I did a fresh install from USB rather than a normal in-place upgrade. Everything went well, the installation is super fast, except that High Sierra does not ship with the libssl headers, so pyenv install fails:

ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.

BUILD FAILED (OS X 10.13 using python-build 1.1.4-2-gf9183b5)

One way to fix this is to install OpenSSL with Homebrew and point to it instead:

This does not work for me though, since I switched to pkgsrc last year. I’ve tried:

CFLAGS="-I/opt/pkg/include" pyenv install 3.5.2

However this also failed because the incompatible expat from pkgsrc and the system. I resolved to solve this by patching the python-build script to always download and compile OpenSSL:

index 7c4efc7..98ee6d2 100755
--- a/plugins/python-build/bin/python-build
+++ b/plugins/python-build/bin/python-build
@@ -1386,7 +1386,7 @@ use_homebrew_readline() {

 has_broken_mac_openssl() {
   is_mac &&
-  [[ "$(/usr/bin/openssl version 2>/dev/null || true)" = "OpenSSL 0.9.8"?* ]] &&
+  # [[ "$(/usr/bin/openssl version 2>/dev/null || true)" = "OpenSSL 0.9.8"?* ]] &&
   ! use_homebrew_openssl

In general I think this is even a better approach than linking to Homebrew’s OpenSSL.