LoginSignup
4
3

More than 5 years have passed since last update.

macOSでPythonをHomebrewでインストールしている場合にPython 3.6 系を使う方法

Posted at

PyCon JP 2018 Tutorialでハマったので共有します。

なぜPython3.6系をインストールするのか

Django のLTSである 1.11 が Python 3.7 に未対応のため。

結論

次の2択。

1. 自分のCellarに残っているPython3.6系に切り替える

失敗するかもしれないけれことを覚悟しつつ次のコマンドを打ってみる。

$ brew switch python 3.6.5_1 # or 3.6.5, 3.6.4. ...

もし、自分のCellarに残っているバージョンがわからなくても、Python 3.6系が残っていれば次のように表示される。

$ brew switch python 3.6.5 # Cellarに無いバージョンを指定した場合
Error: python does not have a version "3.6.5" in the Cellar.
python installed versions: 3.6.5_1, 3.7.0

2. 自分のCellarにPython3.6系が残っていない

上記の方法を行ったときに次のようにPython3.7系しかインストールされていないことがわかった場合の対処方法。

$ brew switch python 3.6.1
Error: python does not have a version "3.6.1" in the Cellar.
python installed versions: 3.7.0

Python 3.6.5_1を次のようにしてインストールできる。

$ brew unlink python
Unlinking /usr/local/Cellar/python/3.7.0... 25 symlinks removed
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb 

# たくさんのメッセージが出てくる
==> Summary
🍺  /usr/local/Cellar/python/3.6.5_1: 4,740 files, 99.3MB

上記が終わったあとに次のコマンドで切り替えられる。

$ brew switch python 3.6.5_1

その他の方法

次の方法が考えられるが、それぞれオーバーキルになりがちなため普通にインストールした。

  1. pyenvの利用
  2. dockerの利用

Reference

4
3
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
4
3