最終更新:2025-05-05 (月) 22:04:12 (66d)
pyenv
Top / pyenv
Simple Python version management
https://github.com/pyenv/pyenv
Ubuntu
インストール
sudo apt update; sudo apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl git libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
curl -fsSL https://pyenv.run | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc echo 'eval "$(pyenv init - bash)"' >> ~/.bashrc
exec "$SHELL"
pyenv-virtualenv
# Load pyenv-virtualenv automatically by adding # the following to ~/.bashrc: eval "$(pyenv virtualenv-init -)"
macOS
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc echo 'eval "$(pyenv init - zsh)"' >> ~/.zshrc
exec "$SHELL"
Windows
使い方
- pyenv install --list (-l) : check a list of Python versions supported by pyenv-win
- pyenv install <version>
- pyenv global <version>
- pyenv local <version>
- pyenv local --unset?
インストール
依存パッケージ
help
Usage: pyenv <command> [<args>] Some useful pyenv commands are: commands List all available pyenv commands duplicate Creates a duplicate python environment 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 update Update the cached version DB rehash Rehash pyenv shims (run this after installing executables) vname Show the current Python version version Show the current Python version and its origin version-name Show the current Python version versions List all Python versions available to pyenv exec Runs an executable by first preparing PATH so that the selected Python 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-win/pyenv-win#readme
インストーラ
- pyenv-installer
https://github.com/pyenv/pyenv-installer
- 下記のpyenvのパッケージをインストールするだけなので依存ライブラリは別に入れておく必要がある
インストール対象
- pyenv
- pyenv-doctor
- pyenv-installer
- pyenv-update?
- pyenv-virtualenv
- pyenv-which-ext?
コマンド (本家)
- pyenv install: Install a Python version using python-build
- pyenv install --list - List all available versions
- pyenv update: Update the cached version DB
- pyenv version: Show the current Python version(s) and its origin
- pyenv versions: List all Python versions available to pyenv
- pyenv doctor: Verify pyenv installation and development tools to build pythons.
- pyenv init?: Verify pyenv installation and development tools to build pythons.
- pyenv uninstall?
- pyenv commands: List all available pyenv commands
切り替え
pyenv local
- 現在のディレクトリ以下にのみ適用したい場合
pyenv global
- 全ディレクトリで適用したい場合
help
Usage: pyenv <command> [<args>] Some useful pyenv commands are: activate Activate virtual environment commands List all available pyenv commands deactivate Deactivate virtual environment doctor Verify pyenv installation and development tools to build pythons. exec Run an executable with the selected Python version global Set or show the global Python version(s) 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(s) 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(s) and its origin --version Display the version of pyenv 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 virtualenv Create a Python virtualenv using the pyenv-virtualenv plugin virtualenv-delete Uninstall a specific Python virtualenv virtualenv-init Configure the shell environment for pyenv-virtualenv virtualenv-prefix Display real_prefix for a Python virtualenv version virtualenvs List all Python virtualenvs found in `$PYENV_ROOT/versions/*'. whence List all Python versions that contain the given executable which Display the full path to an executable
旧
Python/ビルド
環境変数
コマンド
# the sed invocation inserts the lines at the start of the file # after any initial comment lines sed -Ei -e '/^([^#]|$)/ {a \ export PYENV_ROOT="$HOME/.pyenv" a \ export PATH="$PYENV_ROOT/bin:$PATH" a \ ' -e ':a' -e '$!{n;ba};}' ~/.profile echo 'eval "$(pyenv init --path)"' >>~/.profile echo 'eval "$(pyenv init -)"' >> ~/.bashrc
- .profile
export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" echo 'eval "$(pyenv init --path)"'
- .bashrc
echo 'eval "$(pyenv init -)"'
Ubuntuの場合のメモ
.bashrc
export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv virtualenv-init -)"