关于Mac|关于Mac OS 11.0.1下pyenv下载python可能碰到的问题及解决

问题 环境

  • 系统环境:Mac OS 11.0.1
  • pyenv 1.2.20
下载指令
pyenv install 3.6.8

报错内容
Error in installing Python on MacOS and pyenv `BUILD FAILED (OS X 11.0.1 using python-build 20180424)Inspect or clean up the working tree at /tmp/python-build.20201120091233.71993 Results logged to /tmp/python-build.20201120091233.71993.logLast 10 log lines: ./Modules/posixmodule.c:8210:15: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration] 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!"); ^~~~~~~~~~~~~ 1 warning and 1 error generated. make: *** [Modules/posixmodule.o] Error 1 make: *** Waiting for unfinished jobs.... 1 warning generated`

解决 一、进入XCode的Preference > Locations,将command-line tools选择适当的版本
二、运行以下指令
(注本文下载的python版本为3.6.8,如需要下载的为其他版本,则在相应位置更改版本号即可)
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)

可看到这次不会报错,可以下载成功了
检验
pyenv versions

【关于Mac|关于Mac OS 11.0.1下pyenv下载python可能碰到的问题及解决】查看可知python 3.6.8已下载成功

    推荐阅读