I had to install Python 3.7.2 to try out a project. Using pyenv, I encountered a "BUILD FAILED" error. The entire error message is below:
❯ pyenv install 3.7.2
python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Installing Python-3.7.2...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
BUILD FAILED (OS X 15.3.2 using python-build 20180424)
Inspect or clean up the working tree at /var/folders/k0/wdbl3h8d2z3cc7w39t599q380000gn/T/python-build.20250415175136.65981
Results logged to /var/folders/k0/wdbl3h8d2z3cc7w39t599q380000gn/T/python-build.20250415175136.65981.log
Last 10 log lines:
| ^
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wno-cast-function-type -Werror=implicit-function-declaration -I. -I./Include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/ryanlee/.pyenv/versions/3.7.2/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/ryanlee/.pyenv/versions/3.7.2/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -DPy_BUILD_CORE_BUILTIN -c ./Modules/errnomodule.c -o Modules/errnomodule.o
./Modules/posixmodule.c:8409:15: error: call to undeclared function 'sendfile'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
8409 | ret = sendfile(in, out, offset, &sbytes, &sf, flags);
| ^
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wno-cast-function-type -Werror=implicit-function-declaration -I. -I./Include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/ryanlee/.pyenv/versions/3.7.2/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/ryanlee/.pyenv/versions/3.7.2/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -DPy_BUILD_CORE_BUILTIN -c ./Modules/pwdmodule.c -o Modules/pwdmodule.o
1 error generated.
1 warning generated.
make: *** [Modules/posixmodule.o] Error 1
make: *** Waiting for unfinished jobs....
After some digging around, I found a workaround for 3.7.3:
CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 3.7.3 < <(curl -sSL
I figured it might work for 3.7.2. After adapting the command, I got a "zsh: no matches found" error:
> CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
pyenv install --patch 3.7.2 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch?full_index=1)
zsh: no matches found: https://github.com/python/cpython/commit/8ea6353.patch?full_index=1
Googling on this error, it turns out that the "?" from the GitHub URI is tripping up the shell interpreter. So we should add a quote around the URI:
curl -sSL 'https://github.com/python/cpython/commit/8ea6353.patch?full_index=1'
The full command:
CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
pyenv install --patch 3.7.2 < <(curl -sSL 'https://github.com/python/cpython/commit/8ea6353.patch?full_index=1')
And it worked!
❯ CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
pyenv install --patch 3.7.2 < <(curl -sSL 'https://github.com/python/cpython/commit/8ea6353.patch?full_index=1')
python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Installing Python-3.7.2...
patching file 'Misc/NEWS.d/next/macOS/2020-06-24-13-51-57.bpo-41100.mcHdc5.rst'
patching file configure
patching file configure.ac
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.7.2 to /Users/ryanlee/.pyenv/versions/3.7.2