LoginSignup
1
1

More than 1 year has passed since last update.

mac OS Montereyでpyenv installができなくなった時の解決策

Posted at

事象

OSのアップデート後、以下の開発環境にてpyenvでpythonバージョンインストールができなくなり、3時間ほど溶かしたので、備忘録。

開発環境

  • OS Monterey ver12.3
  • シェルはzsh
  • Homebrew経由にてpyenvをインストール済。python3.6系を使用中。pyenv install 3.8.1を、実行したところ以下のエラーが発生
BUILD FAILED (OS X 12.3 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/dz/f45slrd10kd13yxmrsxzg0rr0000gn/T/python-build.20220530202441.23363
Results logged to /var/folders/dz/f45slrd10kd13yxmrsxzg0rr0000gn/T/python-build.20220530202441.23363.log

解決策

  1. xcodeの再インストール
  2. Homebrewにて、zlib, bzip2 をインストール
  3. ~/.zshrc の書き換え
  4. ターミナルにて指定のコマンド実行

xcodeの再インストール

$ xcode-select --install

※ この処理は結構重いみたいで10分ほどかかりました

Homebrewにて、zlib, bzip2 をインストール

参考記事をもとに、zlib, bzip2をインストール。bzip2に関しては、zlibを入れて解決しない人が使っているっぽいので、zlibを入れて解決しない場合に、bzip2を入れるでも良いかも。

参考: Install python 3.8.0 via pyenv on BigSur

~/.zshrc の書き換え

open .zshrc コマンドを叩いて、~/.zshrcに以下の記述を追記

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"

尚、pyenv 関連の最終的な記述は以下

# pyenvの設定
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv 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"

ターミナルにて指定のコマンド実行

以下のコマンドを実行。 ※かなり長いけど、一文。コード内pyenv install --patch 3.8.1の部分は自分のインストールしたバージョンに書き換えて使う。

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

結果、指定バージョンがインストールできた

python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.8.1 to /Users/ogasawarasatoru/.pyenv/versions/3.8.1

$ pyenv versions
  system
* 3.6.5 (set by /Users/ogasawarasatoru/.pyenv/version)
  3.8.1

参考記事

  1. macOS Big Sur にアップグレードした後にpyenv installできなくなった際の私の場合の解決方法
  2. pyenvのgit issue (Python 3.6-3.8 cannot be installed on Mac OS 11.0.1: "implicit declaration of function 'sendfile' is invalid in C99")
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1