LoginSignup
2
2

More than 1 year has passed since last update.

【M1 Mac版】Python3のインストール手順まとめ

Last updated at Posted at 2022-09-26

手順

Homebrewがインストールされていること

1. pyenvのインストール

$ brew install pyenv
$ pyenv -v
実行結果
pyenv 2.3.0

2. pyenvのPathの設定

  • 下記コマンドを1行ずつ実行
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
$ echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(pyenv init -)"' >> ~/.zshrc
$ source ~/.zshrc

pyenvのGitHubに実行するよう記載されている。
Set up your shell environment for PyenvFor Zshを参照

3. pyenvでインストールできるPythonのバージョンを確認

$ pyenv install --list

4. Pythonのインストール

$ pyenv install 3.10.6

listで確認した最新バージョンをインストール(当時3.10.6が最新)

上手くいかない場合はこちらも試す

$ arch -arch x86_64 env PATH=${PATH/\/opt\/homebrew\/bin:/} pyenv install 3.10.6

5. インストールされているPythonを一覧で確認

$ pyenv versions
実行結果
* system (set by /Users/username/.pyenv/version)
  3.10.6
$ python -V
実行結果
Python 2.7.16

インストールはできたが、このままではMacに最初からsystemとして入っているPythonが指定されている為、使用するPythonのバージョンを設定する必要がある。

6. 使用するバージョンを設定して完了

$ pyenv global 3.10.6
$ pyenv versions
実行結果
  system
* 3.10.6 (set by /Users/username/.pyenv/version)
$ source ~/.zshrc
$ python -V
実行結果
Python 3.10.6
2
2
1

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
2
2