LoginSignup
0
0

More than 1 year has passed since last update.

[macOS Big Sur] Homebrew + pyenv

Last updated at Posted at 2021-08-30

MAC バージョン確認

% sw_vers

    ProductName:    macOS
    ProductVersion:    11.5.2
    BuildVersion:    20G95

Pythonバージョン確認

% python -V

    Python 2.7.16

brew バージョン確認

% brew -v

    Homebrew 3.2.9
    Homebrew/homebrew-core (git revision f401485d70; last commit 2021-08-29)

pyenvインストール

% brew install pyenv

    Updating Homebrew...
    ==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
      https://github.com/Homebrew/brew#donations
    ==> Auto-updated Homebrew!
    Updated 1 tap (homebrew/core).
    ==> New Formulae
    alembic                                                      spirv-llvm-translator                                        yt-dlp
    ==> Updated Formulae
    Updated 41 formulae.

    ==> Downloading https://ghcr.io/v2/homebrew/core/m4/manifests/1.4.19
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/m4/blobs/sha256:b22472f659112cf12163bba770d891618b3ada5aaf5baa01516d80fef6214617
    ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:b22472f659112cf12163bba770d891618b3ada5aaf5baa01516d80fef6214617?se=2021-08-30T10%3A10%3A00Z&sig
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/autoconf/manifests/2.71
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/autoconf/blobs/sha256:0aa64f171bac19ce6ac0c0ca697f30658db78cf175550dfde3dbda907b7f2500
    ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:0aa64f171bac19ce6ac0c0ca697f30658db78cf175550dfde3dbda907b7f2500?se=2021-08-30T10%3A10%3A00Z&sig
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/openssl/1.1/manifests/1.1.1l
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/openssl/1.1/blobs/sha256:ff8b2a965c680b4d9baccd60e799d0989e7dc562d2ba81696a9996bab256a6ad
    ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:ff8b2a965c680b4d9baccd60e799d0989e7dc562d2ba81696a9996bab256a6ad?se=2021-08-30T10%3A10%3A00Z&sig
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/pkg-config/manifests/0.29.2_3
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/pkg-config/blobs/sha256:0040b6ebe07f60549800b211343fd5fb3cf83c866d9f62e40f5fb2f38b71e161
    ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:0040b6ebe07f60549800b211343fd5fb3cf83c866d9f62e40f5fb2f38b71e161?se=2021-08-30T10%3A10%3A00Z&sig
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/readline/manifests/8.1
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/readline/blobs/sha256:2cc3a9582e3c7e21eb3c2c8964abd33e9720fb4a9588c626d8424ff8cc9b1aed
    ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:2cc3a9582e3c7e21eb3c2c8964abd33e9720fb4a9588c626d8424ff8cc9b1aed?se=2021-08-30T10%3A10%3A00Z&sig
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/pyenv/manifests/2.0.5
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/pyenv/blobs/sha256:364691f8daf7817287f8d4baeece0f35d103f149af7552a14d5c5f8273902f30
    ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:364691f8daf7817287f8d4baeece0f35d103f149af7552a14d5c5f8273902f30?se=2021-08-30T10%3A10%3A00Z&sig
    ######################################################################## 100.0%
    ==> Installing dependencies for pyenv: m4, autoconf, openssl@1.1, pkg-config and readline
    ==> Installing pyenv dependency: m4
    ==> Pouring m4--1.4.19.big_sur.bottle.tar.gz
    🍺  /usr/local/Cellar/m4/1.4.19: 13 files, 724.4KB
    ==> Installing pyenv dependency: autoconf
    ==> Pouring autoconf--2.71.big_sur.bottle.tar.gz
    🍺  /usr/local/Cellar/autoconf/2.71: 71 files, 3.2MB
    ==> Installing pyenv dependency: openssl@1.1
    ==> Pouring openssl@1.1--1.1.1l.big_sur.bottle.tar.gz
    ==> Regenerating CA certificate bundle from keychain, this may take a while...
    🍺  /usr/local/Cellar/openssl@1.1/1.1.1l: 8,073 files, 18.5MB
    ==> Installing pyenv dependency: pkg-config
    ==> Pouring pkg-config--0.29.2_3.big_sur.bottle.tar.gz
    🍺  /usr/local/Cellar/pkg-config/0.29.2_3: 11 files, 656.8KB
    ==> Installing pyenv dependency: readline
    ==> Pouring readline--8.1.big_sur.bottle.tar.gz
    🍺  /usr/local/Cellar/readline/8.1: 48 files, 1.6MB
    ==> Installing pyenv
    ==> Pouring pyenv--2.0.5.big_sur.bottle.tar.gz
    🍺  /usr/local/Cellar/pyenv/2.0.5: 771 files, 2.6MB

pyenvバージョン確認

% pyenv -v

    pyenv 2.0.5

シェル確認

% env | grep SHELL

    SHELL=/bin/zsh

 % pyenv init

# (The below instructions are intended for common
# shell setups. See the README for more guidance
# if they don't apply and/or don't work for you.)

# Add pyenv executable to PATH and
# enable shims by adding the following
# to ~/.profile and ~/.zprofile:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"

# Load pyenv into the shell by adding
# the following to ~/.zshrc:

eval "$(pyenv init -)"

# Make sure to restart your entire logon session
# for changes to profile files to take effect.

環境変数の登録と読み込み

% cat ~/.zshrc

    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init --path)"
    eval "$(pyenv init -)"

% source ~/.zshrc

Python3の最新バージョン確認

% pyenv install --list | grep ' 3.' | tail
  3.9.0
  3.9-dev
  3.9.1
  3.9.2
  3.9.4
  3.9.5
  3.9.6
  3.10.0rc1
  3.10-dev
  3.11-dev

Python3.9.6 のインストール

% pyenv install 3.9.6

    python-build: use openssl@1.1 from homebrew
    python-build: use readline from homebrew
    Downloading Python-3.9.6.tar.xz...
    -> https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tar.xz
    Installing Python-3.9.6...
    python-build: use readline from homebrew
    python-build: use zlib from xcode sdk
    Installed Python-3.9.6 to /Users/xxxxxx/.pyenv/versions/3.9.6

変更前確認

% pyenv versions
* system (set by /Users/xxxxxx/.pyenv/version)
  3.9.6

Pythonのバージョン変更

% pyenv global 3.9.6
% pyenv versions
      system
    * 3.9.6 (set by /Users/xxxxxx/.pyenv/version)
% python -V
    Python 3.9.6

コマンドリファレンス

コマンド 説明
pyenv install --list インストール可能なPythonのバージョン一覧
pyenv versions インストール済みPythonのバージョン一覧
pyenv install 3.9.6 Python3.9.6をインストール
pyenv global 3.9.6 Pythonのバージョンを3.9.6に変更
pyenv global system Pythonのバージョンをsystemに変更
pyenv local 3.9.6 カレントディレクトリ配下のPythonのバージョンを3.9.6に変更
0
0
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
0
0