Pythonバージョン管理のpyenvの使い方

提供: Python入門
移動: 案内検索
スポンサーリンク

pyenv とは、Pythonのバージョン管理のツールです。複数の Python のバージョンを管理できます。

読み方

pyenv
ぱい えんぶ

概要

アプリケーション毎に依存関係があり、同一の環境で依存関係の異なるアプリケーションの環境を持つことは、困難なケースがあります。 複数の環境を持ち、それを切り替えることで、依存関係の異なるアプリケーションの開発や利用ができるようになります。

Python では

  • virtualenv
  • pyenv

といったものがあります。

インストール

git clone https://github.com/yyuu/pyenv.git ~/.pyenv

zshrc 等のシェルの設定を行います。

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

設定をシェルに読み込ませます(例はzsh)。

source ~/.zshrc

インストール pyenv-installerを使う場合

curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash

実行例

コマンドの引数

Usage: pyenv <command> [<args>]
 
Some useful pyenv commands are:
   commands    List all available pyenv commands
   local       Set or show the local application-specific Python version
   global      Set or show the global Python version
   shell       Set or show the shell-specific Python version
   install     Install a Python version using python-build
   uninstall   Uninstall a specific Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   version     Show the current Python version and its origin
   versions    List all Python versions available to pyenv
   which       Display the full path to an executable
   whence      List all Python versions that contain the given executable
 
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme

コマンドの例

pyenv install --list
インストールできる Python のバージョンを表示する
pyenv install バージョン番号
バージョン番号で指定した Python をインストールする。 pyenv install 3.6.1 みたいな指定をする。
pyenv install versions
インストール済の Python のバージョンを表示する。

インストール済バージョンの表示

$ pyenv versions
* system (set by /home/kaworu/.pyenv/version)
  2.6.9
  2.7.14
  3.3.7
  3.4.8
  3.5.5

関連項目




スポンサーリンク