Skip to main content

pyenv Installation

pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. For more information on pyenv, see github.com/pyenv/pyenv.

Installation

Installation requires you to SSH into your server. If you need help with this, please refer to the how do I connect article.

  1. Make a tmp folder in your home directory.
mkdir -p "$HOME/tmp" && export TMPDIR="$HOME/tmp"
  1. Install pyenv
curl https://pyenv.run | bash
  1. Add the following to your ~/.bashrc file.
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
  1. Reload your shell.
source ~/.bashrc
  1. Install the python version you wish to have usable with pyenv.
pyenv install 3.12.0
  1. Head to the directory where you wish to set the python version from the previous step to be usable in.
cd /path/to/directory
  1. Set the directory pyenv version.
pyenv local 3.12.0
  1. Create an environment in that directory.
pyenv virtualenv {environment-name}
  1. Activate the environment.
pyenv activate {environment-name}

Additional Commands

To get out of the environment, do:

pyenv deactivate

To view the list of environments, do:

pyenv virtualenvs

To uninstall a specific python version, do:

pyenv uninstall 3.12.0

To uninstall a specific environment, do:

pyenv uninstall {environment-name}