Ref: https://www.liquidweb.com/kb/how-to-install-pyenv-on-ubuntu-18-04/
Step #1: Install pyenv and dependencies using:
sudo apt-get update; sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
Step #2: Clone the Repository To install the latest version of pyenv and provide a straightforward method for updating it, run the following command to pull it down from GitHub:
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
Step #3: Configure the Environment Next, to properly configure pyenv for use on the system, run the following block of commands to set some important environment variables and setup pyenv autocompletion:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
Finally, to start using pyenv, restart the shell by running:
root@ubuntu:~# exec "$SHELL"
Step #4: Verify the Installation
To verify that pyenv is installed correctly, we will try installing a new version of Python. First, we will list the available versions of Python:
root@ubuntu:~# pyenv install --list
pyenv is now installed if you see a lot of differnet packages show up.
Clone git repo:
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
Add to bash profiel for auto-activation:
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
pyenv virtualenv <python version you need> <name of env>