Published on

Installing Python 3.8.0+ on your Mac with pyenv

Last Modified on
Last modified on
Authors
Installing Python 3.8.0+ on your Mac with pyenv
Photo by Romina Farias on Unsplash

Recently I wrote a post entitled Installing the latest version of Python on Mac OS Catalina and overriding the old default pre-installed version about installing Python 3.7.7 on Mac OS Catalina with Homebrew. Python 3.7.7 was the latest version of Python that one could install < 3.8.0. At the time, I was totally okay with that. That was before I discovered the Mkdocs documentation generator, which requires Python 3.8.2. It also supports 3.8.3. I checked to make sure!

Python 3.8.0+ requires a different path than Python 3 < 3.8.0 on Mac OS Catalina. I installed Python 3.7.7 using Homebrew, and you can compare the differences in the installation processes by reading both Installing the latest version of Python on Mac OS Catalina and overriding the old default pre-installed version and this post.

After a couple of failed attempts, I finally found the best way to install Python 3.8.0+ on my computer and make Python 3.8.3 the global version of Python. I ended up installing pyenv, the Python version manager, on my computer using Homebrew, and then configuringthe correct path to Python 3.8.3 in my .zshrc file located in my home directory. I could not afford to wait around for Homebrew to support 3.8.0+, and pyenv is a great solution in general! It is akin to nvm, the Nodejs version manager. The concept is the same, and both made installing Nodejs and Python easy on Mac OS Catalina!

This post assumes that you have Homebrew installed on your Mac computer with OS Catalina installed as well.

First I ran brew update, to update Homebrew. One should always run that command before installing something new with Homebrew.

Then I ran brew install pyenv. That installed the Python version manager pyenv.

Then I had to add the pyenv path to my zsh profile, .zshrc, located in my home directory.

echo 'export PATH="$(pyenv root)/shims:$PATH"' >> ~/.zshrc

This command copied the command export PATH="$(pyenv root)/shims:$PATH" to my .zshrc file. The following was added to the bottom of .zshrc:

export PATH="$(pyenv root):$PATH"

Next, I wanted to check what Python versions are available through pyenv, so I could execute the following command in Terminal:

pyenv install --list

A long list of things were returned, but I will only list what versions of the Real Python were available to me (6.28.20) at the time of writing this post:

2.1.3
  2.2.3
  2.3.7
  2.4.0
  2.4.1
  2.4.2
  2.4.3
  2.4.4
  2.4.5
  2.4.6
  2.5.0
  2.5.1
  2.5.2
  2.5.3
  2.5.4
  2.5.5
  2.5.6
  2.6.6
  2.6.7
  2.6.8
  2.6.9
  2.7.0
  2.7-dev
  2.7.1
  2.7.2
  2.7.3
  2.7.4
  2.7.5
  2.7.6
  2.7.7
  2.7.8
  2.7.9
  2.7.10
  2.7.11
  2.7.12
  2.7.13
  2.7.14
  2.7.15
  2.7.16
  2.7.17
  2.7.18
  3.0.1
  3.1.0
  3.1.1
  3.1.2
  3.1.3
  3.1.4
  3.1.5
  3.2.0
  3.2.1
  3.2.2
  3.2.3
  3.2.4
  3.2.5
  3.2.6
  3.3.0
  3.3.1
  3.3.2
  3.3.3
  3.3.4
  3.3.5
  3.3.6
  3.3.7
  3.4.0
  3.4-dev
  3.4.1
  3.4.2
  3.4.3
  3.4.4
  3.4.5
  3.4.6
  3.4.7
  3.4.8
  3.4.9
  3.4.10
  3.5.0
  3.5-dev
  3.5.1
  3.5.2
  3.5.3
  3.5.4
  3.5.5
  3.5.6
  3.5.7
  3.5.8
  3.5.9
  3.6.0
  3.6-dev
  3.6.1
  3.6.2
  3.6.3
  3.6.4
  3.6.5
  3.6.6
  3.6.7
  3.6.8
  3.6.9
  3.6.10
  3.6.11
  3.7.0
  3.7-dev
  3.7.1
  3.7.2
  3.7.3
  3.7.4
  3.7.5
  3.7.6
  3.7.7
  3.7.8
  3.8.0
  3.8-dev
  3.8.1
  3.8.2
  3.8.3
  3.9.0b3
  3.9-dev
  3.10-dev

And after I installed the Python versions I wanted, I ran the following command to see what versions were installed on my computer via pyenv:

pyenv versions

For me, it returned:

system
3.8.2
* 3.8.3 (set by /Users/mariacam/.pyenv/version)

The system version is the Mac OS system version (2.7.14) which is included with pyenv as well, and 3.8.2 and 3.8.3 were installed by me.

Then I had to set a global version for my computer, so I executed the following command:

pyenv global 3.8.3

When I ran the command

python --version

the following was returned:

Python 3.8.3

And it worked!

If you want to use a different version of Python using pyenv in a particular project, you would run the following command:

pyenv local 3.8.2

for example. Just change the Python version number to the one you want. You just have to make sure you already have it installed on your computer via pyenv.

Now my Mkdocs documentation generator works perfectly. I just had to make sure that I updated pip to the latest version before everything worked smoothly. I got the version I needed for Mkdocs support via their website, and then updated pip with the following command:

pip install --upgrade pip

pip comes with Python, but you may want to just upgrade to the latest version. That is what I did, because I did not have the later version that was required for Mkdocs, so I upgraded pip.