1 Symptom

If you install Python using Pyenv on Mac Big Sur, you will get the following error message

BUILD FAILED (OS X 11.2.1 using python-build 1.2.24.1) Inspect or clean up the working tree at The/var/folders/c1 / bsm2j06q5kz4r0y99ynm40000gn 947 / T/python - build. 20210323112319.19225 the Results logged to / var/folders/c1 / bsm2j06q5kz4r0y99ynm40000gn 947 / T/python - build. 20210323112319.19225 the log Last 10 log lines: ret = sendfile(in, out, offset, &sbytes, &sf, flags); ^ ./Modules/posixmodule.c:10432:5: warning: code will never be executed [-Wunreachable-code] Py_FatalError("abort() called from Python code didn't abort!" ); ^~~~~~~~~~~~~ clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall - I/Library/Developer/CommandLineTools/SDKs/MacOSX SDK/usr/include - I/usr/local/opt/[email protected] / include -I/usr/local/opt/bzip2/include -I/usr/local/opt/readline/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include - I/Library/Developer/CommandLineTools/SDKs/MacOSX SDK/usr/include - I/usr/local/opt/[email protected] / include -I/usr/local/opt/bzip2/include -I/usr/local/opt/readline/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -I. -I./Include -i/usr/local/opt/readline/include -i/usr/local/opt/readline/include -i/usr/local/opt/[email protected] / include -i/Users/didi. Pyenv/versions / 3.6.8 / include - I/usr/local/opt/readline/include - I/usr/local/opt/readline/include -i/usr/local/opt/[email protected] / include - / Users/I didi /. Pyenv/versions / 3.6.8 / include - DPy_BUILD_CORE - c ./Modules/pwdmodule.c -o Modules/pwdmodule.o 1 warning and 1 error generated. make: *** [Modules/posixmodule.o] Error 1 make: *** Waiting for unfinished jobs.... 1 warning generated.Copy the code

2 Solutions

1 reinstall zlib bzip2

brew reinstall zlib bzip2
Copy the code

2 update .zshrc or .bashrc dependent on your shell

export PATH="$HOME/.pyenv/bin:$PATH"
export PATH="/usr/local/bin:$PATH"

eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export LDFLAGS="-L/usr/local/opt/zlib/lib -L/usr/local/opt/bzip2/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include"
Copy the code

3 install python 3.6.8, you can change the version

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.6.8 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
Copy the code

4 If it didn’t work try and repeat step 3 again

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
Copy the code