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"' >> ~/.bashrcecho 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrcecho 'eval "$(pyenv init -)"' >> ~/.bashrcecho 'export PYENV_ROOT="$HOME/private/.pyenv"' >> ~/.profileecho 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profileecho 'eval "$(pyenv init -)"' >> ~/.profilesource ~/.bashrccurl 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 --listThe following command will install the latest Python 3.11.x:pyenv install 3.11This command activates Python 3.11 in the current directory:
pyenv local 3.11You can also change the Python version globally for your account: pyenv global 3.11For more advanced usage and configuration options, refer to the pyenv documentation.