乐趣区

关于macos:关于Mac-OS-1101下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.log

Last 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

查看可知 python 3.6.8 已下载胜利

退出移动版