Skip to content

Instantly share code, notes, and snippets.

@adamharder
Last active May 7, 2021 15:26
Show Gist options
  • Select an option

  • Save adamharder/91dcec282e3b911192c68a977924924c to your computer and use it in GitHub Desktop.

Select an option

Save adamharder/91dcec282e3b911192c68a977924924c to your computer and use it in GitHub Desktop.
Python setup for Ubuntu 20

Adapted from https://www.laac.dev/blog/setting-up-modern-python-development-environment-ubuntu-20/

Install zsh

sudo apt-get install zsh -y

https://ohmyz.sh/

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

install Pyenv

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.

Installing Pyenv

  1. 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

  2. Install pyenv using the installer [https://github.com/pyenv/pyenv-installer#installation--update--uninstallation].

    curl https://pyenv.run | bash

  3. Follow the instructions [https://github.com/pyenv/pyenv#basic-github-checkout] to update your .bashrc with the pyenv initialization step and environment variable.

  4. Restart your shell: exec $SHELL.

  5. Validate the installation: pyenv --version.

  6. Install your preferred version of Python: pyenv install 3.8.5

  • Note: this could take some time.
  1. Set the newly installed python as your global interpreter: pyenv global 3.8.5

  2. Validate your global interpreter is the newly installed Python: which python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment