Skip to content

How to set up pyenv

Source: https://github.com/pyenv/pyenv

Install Dependencies

sudo apt update sudo apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

Automatic Installer

  • curl https://pyenv.run | bash
  • insert the following into .bashrc bash export PYENV_ROOT="$HOME/.pyenv" [[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)"
  • and complete by running source ~/.bashrc

Operation

  • list versions pyenv install -l
  • install version pyenv install 3.12
  • switch between versions:
    • for current shell only: pyenv shell 3.12
    • select when in current directory: pyenv local 3.11
    • select globally for user account: pyenv global 3.10
  • remove version pyenv uninstall 3.12