Adapted from https://www.laac.dev/blog/setting-up-modern-python-development-environment-ubuntu-20/
sudo apt-get install zsh -y
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Pyenv helps us by installing Python 3.7 on our Ubuntu 20.04 system. The default system version is 3.8.2 which doesn’t work for our current project. Pyenv allows us to install the latest 3.7 for our Django project’s development environment. Also, once our project upgrades to Django 3.1 and Python 3.8, we use pyenv to install Python 3.8.5 so that we don’t use the system interpreter.
-
Install the prerequisite packages for Ubuntu [https://github.com/pyenv/pyenv/wiki/Common-build-problems].
sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
-
Install pyenv using the installer [https://github.com/pyenv/pyenv-installer#installation--update--uninstallation].
curl https://pyenv.run | bash
-
Follow the instructions [https://github.com/pyenv/pyenv#basic-github-checkout] to update your .bashrc with the pyenv initialization step and environment variable.
-
Restart your shell:
exec $SHELL. -
Validate the installation:
pyenv --version. -
Install your preferred version of Python:
pyenv install 3.8.5
- Note: this could take some time.
-
Set the newly installed python as your global interpreter:
pyenv global 3.8.5 -
Validate your global interpreter is the newly installed Python:
which python