再bigsur上使用pyenv管理多版本python存在这一些路径上的问题,再虚拟环境的创建和使用上不存在太大问题,但是再python版本安装上,就很糟心。记录一下Mac bigsur上使用pyenv安装python是遇到的问题和解决方法。
问题:
安装时回报错没有sendfile这个方法,是因为系统中文件变化引起的。
异常如下:
$ pyenv install 3.8.0
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.0.tar.xz...
-> https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz
Installing Python-3.8.0...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
BUILD FAILED (OS X 11.5.2 using python-build 20180424)
Inspect or clean up the working tree at /var/folders/y3/_thcf6bd3ts0bmhf7q6p565c0000gn/T/python-build.20210923184202.92770
Results logged to /var/folders/y3/_thcf6bd3ts0bmhf7q6p565c0000gn/T/python-build.20210923184202.92770.log
Last 10 log lines:
^
clang -c -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/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 -Werror=implicit-function-declaration -I./Include/internal -I. -I./Include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/xxxxxxx/.pyenv/versions/3.8.0/include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/xxxxxxx/.pyenv/versions/3.8.0/include -DPy_BUILD_CORE -o Modules/gcmodule.o Modules/gcmodule.c
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/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 -Werror=implicit-function-declaration -I./Include/internal -I. -I./Include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/xxxxxxx/.pyenv/versions/3.8.0/include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/xxxxxxx/.pyenv/versions/3.8.0/include -DPy_BUILD_CORE_BUILTIN -DPy_BUILD_CORE_BUILTIN -I./Include/internal -c ./Modules/posixmodule.c -o Modules/posixmodule.o
./Modules/posixmodule.c:9084:15: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
ret = sendfile(in, out, offset, &sbytes, &sf, flags);
^
1 error generated.
make: *** [Modules/posixmodule.o] Error 1
make: *** Waiting for unfinished jobs....
1 warning generated.
针对这个问题github上有对应的解决方法,使用cpython的patch可以临时修改安装文件,解决bigsur上无法安装的问题。
具体命令如下,以python3.8为例:
pyenv install 3.8.0 --patch < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch)