インストール
クイックインストール
# mac
$ brew install pyenv
ソースのインストール
# Check out pyenv
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
# Define environment variable PYENV_ROOT
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
# Add pyenv init to your shell
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
# Restart your shell
exec "$SHELL"
# Just run!
$ pyenv -v
pyenv 1.2.17-1-g89786b90
注意:
- zshの:修正する
~/.zshrc
代わりに、ファイルを~/.bash_profile
。 - Ubuntuの、Fedoraは:修正する
~/.bashrc
代わりに、ファイルを~/.bash_profile
。
使用
必要なPythonのバージョンをインストールします。
# install python
$ pyenv install 2.7.8
$ pyenv install 3.8.2
$ pyenv versions
system
2.7.8
* 3.8.2 (set by /Users/youshu/.pyenv/version)
一般的には3.8が十分である、2.7があります。
あなたはバージョンのサポートわからない場合、あなたは、Pythonのバージョンのインストールをサポートpyenv表示することができます。
$ pyenv install --list
パイソンの指定されたバージョンを使用します。
$ pyenv local 2.7.8
$ python -V
Python 2.7.8
使用local
に必要な効果が世界的に、我々が使用する必要がある場合は、現在のシェルのコマンドだけで、指定されたバージョンに切り替えるglobal
コマンドを:
$ pyenv global 3.8.2
$ python -V
Python 3.8.2
最新バージョンを使用して
バージョンサポートされていないpyenvリストが必要な場合は、手動で追加することができます。~/.pyenv/plugins/python-build/share/python-build/
Directoryは、ダウンロードのさまざまなバージョンに保存され、ファイル名は、Pythonのバージョンの名前です。
$ ls ~/.pyenv/plugins/python-build/share/python-build/
2.1.3 3.3.6 anaconda-1.6.1 ironpython-2.7.7 miniconda3-3.9.1 pypy-5.1 pypy3.3-5.2-alpha1
...
ここでの内容3.8.2は以下のとおりです。
$ cat ~/.pyenv/plugins/python-build/share/python-build/3.8.2
#require_gcc
prefer_openssl11
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1
install_package "openssl-1.1.0j" "https://www.openssl.org/source/openssl-1.1.0j.tar.gz#31bec6c203ce1a8e93d5994f4ed304c63ccf07676118b6634edded12ad1b3246" mac_openssl --if has_broken_mac_openssl
install_package "readline-8.0" "https://ftpmirror.gnu.org/readline/readline-8.0.tar.gz#e339f51971478d369f8a053a330a190781acb9864cf4c541060f12078948e461" mac_readline --if has_broken_mac_readline
if has_tar_xz_support; then
install_package "Python-3.8.2" "https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz#2646e7dc233362f59714c6193017bb2d6f7b38d6ab4a0cb5fbac5c36c4d845df" ldflags_dirs standard verify_py38 copy_python_gdb ensurepip
else
install_package "Python-3.8.2" "https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz#e634a7a74776c2b89516b2e013dda1728c89c8149b9863b8cea21946daf9d561" ldflags_dirs standard verify_py38 copy_python_gdb ensurepip
fi
ヘルプ
$ pyenv -h
Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
--version Display the version of pyenv
commands List all available pyenv commands
exec Run an executable with the selected Python version
global Set or show the global Python version
help Display help for a command
hooks List hook scripts for a given pyenv command
init Configure the shell environment for pyenv
install Install a Python version using python-build
local Set or show the local application-specific Python version
prefix Display prefix for a Python version
rehash Rehash pyenv shims (run this after installing executables)
root Display the root directory where versions and shims are kept
shell Set or show the shell-specific Python version
shims List existing pyenv shims
uninstall Uninstall a specific Python version
version Show the current Python version and its origin
version-file Detect the file that sets the current pyenv version
version-name Show the current Python version
version-origin Explain how the current Python version is set
versions List all Python versions available to pyenv
whence List all Python versions that contain the given executable
which Display the full path to an executable
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme
参照
1、pyenv / pyenv:シンプルなPythonのバージョン管理
https://github.com/pyenv/pyenv