Install pyenv.
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bashNOTE: curl | bash is a risky command, make sure to execute them from trusted source only.
Add the following to ~/.bash_profile, ~/.profile or ~/.bashrc.
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"NOTE: I am using Lubuntu 16.04, and only ~/.bashrc works.
Start a new terminal or run source ~/.bashrc.
Check for update.
pyenv updateInstall latest python.
pyenv install 3.7.0NOTE: Check latest python version
NOTE: Refer to Ubuntu 18.04 Pyenv Build Python 3.7 Common Error.
Check for available versions.
pyenv versionsCreate a pyenv virtualenv named test.
pyenv virtualenv 3.7.0 testActivate virtualenv
pyenv activate testDeactivate virtualenv
pyenv deactivateList all virtualenv
pyenv virtualenvsDelete/Uninstall virtualenv
pyenv uninstall envNOTE: Refer to Install Python (Make from Source) or apt-get as well.