LoginSignup
2
1

More than 1 year has passed since last update.

pyenv インストール& python バージョン管理

Posted at

Python3で開発するためpythonのバージョンを変更したい時に、pythonのバージョン管理ツールpyenvを使うと便利です

環境: Mac OSX

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!
.
.
.
==> Installing pyenv
==> Pouring pyenv--2.0.2.arm64_big_sur.bottle.tar.gz
🍺  /opt/homebrew/Cellar/pyenv/2.0.2: 762 files, 2.6MB

インストールしたいPythonのバージョンをリストの中から確認

$ pyenv install --list
(実行後の出力)
Available versions:
  2.1.3
  2.2.3
..
  3.9.4
  3.9.5
  3.10.0b3
  3.10-dev
  3.11-dev
..
  stackless-3.5.4
  stackless-3.7.5

Pythonのバージョンを指定してインストール

$ pyenv install 3.9.5
(実行後の出力)
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.5.tar.xz...
-> https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tar.xz
Installing Python-3.9.5...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.9.5 to /Users/takuma/.pyenv/versions/3.9.5

インストール後に読み込み設定

terminal
$ echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
$ eval "$(pyenv init --path)"

これでバージョンを確認するとインストールしたバージョンに変わっているはずです。

$ python -V
3.9.5

<参考サイト>
pyenvにより、pythonのバージョンを変更する
pyenvでpython環境構築
Simple Python Version Management: pyenv

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