Installing and managing multiple Python versions with pyenv
This tutorial provides instructions on how to install pyenv on your hosting account. You can use pyenv to install different Python versions and use them on a per-directory basis.
Prerequisites
You need SSH access to the server in order to make the changes described in this tutorial. If you haven't set up SSH for your account yet, you should do this now.
In your hosting Control Panel > SSH Access section > Additional tools, make sure that Compiling tools (gcc, g++) and Network tools are enabled.
Installation
To install pyenv, connect to your account over SSH and run the following commands:
echo 'export PYENV_ROOT="$HOME/private/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'export PYENV_ROOT="$HOME/private/.pyenv"' >> ~/.profile
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.profile
source ~/.bashrc
curl https://pyenv.run | bashNote: Executing "source ~/.bashrc" may result in the error "-bash: pyenv: command not found". You can disregard this error and execute the last command.
These are the same commands as in the official installation instructions. The only difference is that pyenv is installed in ~/private/.pyenv instead of ~/.pyenv.
To verify that pyenv is installed correctly, run:
pyenv --version
Some examples on how to use pyenv
You can see a list of all available Python versions with:
pyenv install --list
The following command will install the latest Python 3.11.x:
pyenv install 3.11
This command activates Python 3.11 in the current directory:
pyenv local 3.11
You can also change the Python version globally for your account:
pyenv global 3.11
For more advanced usage and configuration options, refer to the pyenv documentation.