Install Python 3 (The Easy Way)

Behold! A Tutorial on how To Install Python3 The Lazy Way

Installing Python 3 is your gateway to the world of programming and endless possibilities. Data Science, AI, Automation, You name it!

Traditional Python 3 Installation

The traditional way to install python 3 is to download the official installer from python.org/downloads. It’s not a bad way to go. You might wonder why anyone would want to use another option?

Optionality.

Bouncing between versions can be a pain. If you want to see an easy way to handle python versions stick around for the pyenv section.

If going the traditional route you want to make sure to select “Add Python to PATH” when prompted otherwise python will not work untill you manually add it. (It’s a major pain in the rear if you mess this up)

pyenv

What it pyenv?

Pyenv is a tool for installing and managing multiple python versions. It is not unheard of for you to need to change versions of python for different projects. If you want to make life easy on yourself consider using pyenv.

pyenv does not officially support windows, but there is a windowsversion available as a separate project pyenv-win. Alternatively you can use the Windows Subsystem for Linux (WSL) to install pyenv on windows using the mac/linux technique show below.

Pyenv Installation

You can install pyenv on MacOS, Linux, and Windows. MacOs and Linux installations follow a similar pattern. Windows has a few extra steps but it’s not bad. Let’s go over the installation for each operating system.

Windows

See the pyenv-win installation docs for how to complete the installation on windows. Once you complete the installation jump to the next step in the tutorial titled List Available Versions

MacOS

Here is a link to the official docs on how to install on MacOS

brew update
brew install pyenv

Linux

Here is a link to the official docs on how to install with bash

curl https://pyenv.run | bash

List Available Versions

pyenv install --list

As you can see there are more versions than you can shake a stick at. Let’s filter it down to 3.11

pyenv install --list | grep 3.11

Install Python Version

Once you find a version you want to install go ahead and invoke the install command along with the version you want to install.

pyenv install 3.12.6

If you run into errors on MacOS or Linux consider reviewing if you have the python build dependencies installed. See the wiki article on Suggested Build Environment for more information.

List Installed Versions of Python

After you install one or more versions you might want to see what is available on your system. Run the following command to list the installed versions.

pyenv versions

The version with an * is the currently active version. You can change that version at a global and local level.

Uninstall Python Version

If you need to uninstall a python version you can use the following command.

pyenv uninstall 3.12.6

Set Global Version

Let’s set the global version.

A global version is the version that your shell will default to unless you override it.

pyenv global 3.12.2

Once you set the global version you can verify what version of python you are using by running the following command.

python --version

Alternatively, you can run the following command

python -V

A Few More Things

Set Local Python Version

At the project level you may want to enforce a version of python. Run the following command to set the local version.

pyenv local 3.12.6

Verify the python version

python -V

Verify Global Version of Python

pyenv versions

Upgrade pip

Why is pip not updated upon installalation? It’s a good question. All I know is if you do not update pip you will get warnings about it. So let’s update pip.

python -m pip install --upgrade pip

Bytecode Setting

If you want to avoid having .pyc files getting sprinkled all over your code base you can set an environment variable.

export PYTHONDONTWRITEBYTECODE=1

Pipenv Virtual Environments

The standard way to manage python virtual environments is to use venv. This is built into python so you do not need to install anything. There is a very nice alternative to venv called pipenv.

Lazy developers love pipenv. It has some quality of life doodads you just don’t get with venv It is a popular alternative to venv and is activly maintained. Let’s install it globally.

Install pipenv with the following command.

pip install --user pipenv

Alternativly, you can review the docs more detailed options. pipenv.pypa.io/en/latest

Wrapping Up

You now have python 3 installed and are ready to start building!