LoginSignup
6
6

More than 5 years have passed since last update.

MacでPythonに好きなバージョンを入れて切り替えられるようにする

Last updated at Posted at 2018-10-16

Python3.7.xを使っていたが、諸事情でPython3.6.6の必要がでたので変更

環境
MacbookPro15(2017)
MacOS Mojave 10.14
Python3.7.x

Pyenvをインストールする

pyenvがなければインストールする

$ brew install pyenv

pyenvを使って欲しいバージョンを指定する

$ pyenv install 3.6.6

Build Filedなどが出て失敗したら、xcode-selectがないとなるのでいれる

$ xcode-select --install

Mojaveだとこんなエラーがでてしまう

zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1

最新版にはmacOS SDK headerがないのでインストール

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

"xcode-selectの最新バージョン(2354)にMojave用のmacOS SDK headerがデフォルトで入っていないのが原因のようです。
https://qiita.com/zreactor/items/c3fd04417e0d61af0afe"

pyenvを使って好きなバージョンを適用させる

pyenvにパスを通す

$ touch .bash_profile
$ export PATH="$HOME/.pyenv/shims:$PATH"
$ source .bash_profile

あとはセットするだけ
セットされているものを確認

$ pyenv versions
*  system
   3.6.6 (set by /Users/.python-version)

使いたいバージョンをセットして確認

$ pyenv global 3.6.6
$ pyenv versions
   system
* 3.6.6 (set by /Users/.python-version)
$ python -V
Python 3.6.6
6
6
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
6
6