LoginSignup
10
9

More than 1 year has passed since last update.

macOS Monterey 12.3「python2.7廃止」への対応

Last updated at Posted at 2022-03-15

macOS Monterey 12.3 Release Notes より

Python
Deprecations
Python 2.7 was removed from macOS in this update. Developers should use Python 3 or an alternative language instead. (39795874)

python2.7が廃止になったことに伴って、デフォルトのzsh上でpythonコマンドが使えなくなったため、pyenvを導入してpython環境を構築した。

zsh
# formulaeの最新バージョンを取得して、pyenvをインストールする。
% brew update
% brew install pyenv
# pyenvのpath読み込みとpyenvのcompletionを有効化するようにzsh起動時の設定をする。
% echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
% echo 'eval "$(pyenv init -)"' >> ~/.zshrc
#brewコマンド実行時にpyenvのpathを読み込むようにzsh起動時の設定をする。
% vim ~/.zshrc
~/.zshrc
# 最終行に追加する。
alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew'
zsh
# zshの設定ファイルを再読み込みする。
% source ~/.zprofile 
% source ~/.zsh
# pythonのインストール可能なバージョンを確認する。
% pyenv install --list
# python2系とpython3系の最新版をインストールする。
% pyenv install 2.7.18
% pyenv install 3.10.2
# インストールしたバージョンをglobalに設定する。
% pyenv global 2.7.18 3.10.2 # 2系を先に書くこと。
# インストールしたコマンドがglobalに効いていることを確認する。
% python --version
Python 2.7.18
% python3 --version
Python 3.10.2

参考
pyenv

10
9
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
10
9