macOS Big Surにアップデート後、pyenvを使用したpythonインストールが失敗するようになった問題の対処法

・MacOS Big Sur 11.2.1 
・xcode.app: 12.4
・pyenv: 1.2.22

#### こんなエラー
``` shell
BUILD FAILED (OS X 11.2.1 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/7t/s4sxvwqd5pqcy3jh_n5vfpjr0000gn/T/python-build.20210221175447.57865
Results logged to /var/folders/7t/s4sxvwqd5pqcy3jh_n5vfpjr0000gn/T/python-build.20210221175447.57865.log

Last 10 log lines:
extern int _NSGetExecutablePath(char* buf, uint32_t* bufsize)                 __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0);
                                                     ^
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include   -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/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/~/.pyenv/versions/3.8.2/include  -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/~/.pyenv/versions/3.8.2/include   -DPy_BUILD_CORE_BUILTIN  -DPy_BUILD_CORE_BUILTIN -I./Include/internal -c ./Modules/posixmodule.c -o Modules/posixmodule.o
./Modules/posixmodule.c:9197: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.
```

### App StoreからXcodeをインストールする（時間掛かるカモ）
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/357470/6d543d81-b667-f565-6e83-9296aba3e2e1.png)

### アクティブデベロッパディレクトリに、先ほどインストールしたXcodeアプリケーションのDeveloperディレクトリを指定する

``` shell
$ sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
```

### xcodebuildを実行する。
``` shell
sudo xcodebuild -runFirstLaunch
```

↓とりあえずエンターキー押す。

``` shell
You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.

Hit the Return key to view the license agreements at '/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf'
```

↓agree と入力してエンター

``` shell
.
..
...
By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel]
```

``` shell
By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel] agree

You can view the license agreements in Xcode's About Box, or at /Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf

Install Started
1%.........20.........40.........60.........80........Install Succeeded
```
Install Succeededが表示されれば完了です



### python3.8.5インストール
``` shell
$ pyenv install 3.8.5

python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Installing Python-3.8.5...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.8.5 to /Users/~/.pyenv/versions/3.8.5
```

python 3.9.0もインストールできた。

### python3.8.2インストール
~~python3.8.2 および それより下のバージョンについては相変わらずエラーが出てしまう状態。~~
[issues](https://github.com/pyenv/pyenv/issues/1746#issuecomment-736750003)より、下記コマンドで3.8.2はインストールできました。
ただ、修正対応も頑張ってくれているっぽい。

``` shell
$ 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.8.2 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
```

### python3.7.8インストール
~~3.7系は上記コマンドでも相変わらずエラー。。。（上記patchはMacOS v11サポート用だから、v3.7はまた別?）~~
3.7.8はpyenv installで普通にインストールできたので、3.7系も大丈夫かな・・・。（3.7.Xによってはエラーになるかもしれない）

``` shell
$ pyenv install 3.7.8
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Installing Python-3.7.8...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.7.8 to /Users/~/.pyenv/versions/3.7.8 
```