Tested only on Ubuntu 18.04 and KDE Neon User Edition (based on Ubuntu 18.04).
will probably work on other newer versions, with no changes, or with few changes in non-python dependencies (apt-get
packages)
NOTE: Don't create a .sh file and run it all at once. It will not work. Copy, paste, and execute each command below manually. :-)
# DO NOT RUN THIS AS A ROOT USER
# Enter your password when prompted.
# your user must be allowed to run "sudo"
sudo bash -c "echo -e 'Starting...\n'"
sudo apt-get update;
# install most common python interpreter itself compile dependencies
sudo apt-get install aria2 build-essential curl git libbz2-dev libffi-dev liblzma-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libssl-dev llvm make tk-dev wget xz-utils zlib1g-dev --yes;
# install pyenv
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
# install a virtualenvwrapper plugin to pyenv
git clone https://github.com/pyenv/pyenv-virtualenvwrapper.git $HOME/.pyenv/plugins/pyenv-virtualenvwrapper
# add pyenv required configurations
if ! egrep -q "^[#]{4}[[:space:]]pyenv[[:space:]]config$" "${HOME}/.bashrc" ; then echo -e "\n\nsetup pyenv configuration:\nThe following content was inserted at the end of the ${HOME}/.bashrc file\n"; echo -e '\n#### pyenv config\nif [ -f "$HOME/.pyenv/bin/pyenv" ] && ! type -P pyenv &>/dev/null ; then\n export PYTHON_CONFIGURE_OPTS="--enable-shared"\n export CFLAGS="-O2"\n export PYTHON_BUILD_ARIA2_OPTS="-x 10 -k 1M"\n export PATH="$HOME/.pyenv/bin:$PATH"\n eval "$(pyenv init -)"\n eval "$(pyenv virtualenv-init -)"\n if [[ ! "$(pyenv which python)" == "/usr/bin/python" ]] ; then \n pyenv virtualenvwrapper_lazy;\n fi\nfi\n#### pyenv config end' | tee --append "${HOME}/.bashrc"; source "$HOME/.bashrc"; else echo -e "\n\npyenv configuration already installed in $HOME/.bashrc"; fi
# reload .bashrc to run pyenv configurations
source $HOME/.bashrc
# download and compile python 3.8.2
pyenv install 3.8.2
# download and compile python 2.7.17
pyenv install 2.7.17
# set "python", "python3", "python3.8" to point python3.8.2, and "python2" and "python2.7" to point python2.7.17
pyenv global 3.8.2 2.7.17
# reload .bashrc to run pyenv configurations again
source $HOME/.bashrc
python3 -m pip install pip setuptools wheel virtualenv virtualenvwrapper -U
python2 -m pip install pip setuptools wheel virtualenv virtualenvwrapper -U