Installing Python 3 and Pyenv on MacOS, Windows, and Linux

We will be using the AWS Lambda runtime for the latest stable version of Python 3 - `python3.7`.

Installing Python 3 and Pyenv on MacOS, Windows, and Linux#

We will be using the AWS Lambda runtime for the latest stable version of Python 3 - python3.7.

AWS supports a few different runtime environments for python, so if we ever need a particular version, we will need to check that it’s supported by lambda first. A full list of supported runtime versions is available on the AWS Documentation page for Lambda Runtimes.

Check for already installed python versions#

If we are using an operating system like Linux or Mac OS - we may already have some version of python installed on our local development machine. This version of python, commonly referred to as the system python, is rarely the latest version that we need for development. We can confirm if we have a system python version installed and see what version it is with the command python --version, as shown below.

The output above indicates that the system version of python installed is much older than 3.7. In other cases, the command above could fail completely, indicting that python is not installed at all. In cases where older are versions present,it is unsafe to update system python directly. Updating it can break certain tools that our operating system needs for essential tasks, including dependency management software. Fortunately, there is a tool called pyenv that will allow us to safely install the latest python version - regardless of whether we have a system python version installed or not.

Install Pyenv#

Pyenv is an open-source tool used for managing multiple python environments. It allows developers to define which version of python to use on a per-project basis. It's similar to the better-known tool that is commonly used in ruby development - rbenv. Prior to pyenv becoming popular, many python developers used virtualenv to manage environment versions. virtualenv is still widely used - but it lacks some crucial features that pyenv provides for standardized installation methods.

We will walk through the most common installation scenarios here, but if you encounter issues, consult the full installation instructions for the project: https://github.com/pyenv/pyenv#installation

Different operating systems have different dependency needs, the latest of which are documented here: https://github.com/pyenv/pyenv/wiki/Common-build-problems

Installing pyenv on Mac OS using homebrew#

Many developers may already have homebrew installed. It's a widely used dependency manager for Mac OS that provides installation packages for many open-source software projects. The commands to install brew are provided below.

  • Install dependencies for brew

  • Install brew

  • Install dependencies pyenv requires

  • If using Mojave or above, use this command to install an additional required dependency:

  • Install pyenv

  • Update the shell to ensure autocomplete for pyenv is functional

Pyenv on Windows#

If using a version of Windows with Windows Subsystem for Linux configured then skip down to instructions for Ubuntu 18.04

Otherwise - we will need to use a pyenv fork, pyenv-win. The instructions underneath the “install by zip” instructions in the pyenv-win wiki provide instructions for pyenv-win installation.

Pyenv on Amazon Linux 2#

The following commands will install the required pyenv dependencies on Amazon Linux 2

Once dependencies are installed, use the pyenv-installer to finish installation.

Pyenv on Ubuntu Linux 18.04 {id:install-pyenv-ubuntu}#

The following commands will install the required pyenv dependencies on Ubuntu Linux 18.04