Mac comes with Python 2.7 pre-installed, but some newer AI libraries prefer you use Python 3+. Here's how to configure your Mac so that you can easily install any version of Python. If you're a Ruby developer, you'll likely understand the power behind Ruby Version Manager or rbenv. This is pretty much the same thing for Python.

Step 1 - Install Homebrew

Since we will be using Homebrew manager to install our Python manager, here's a quick tutorial on how to install Homebrew for Mac users.

brew update

Step 2 - Install pyenv

pyenv is the python package manager.

brew install pyenv

Step 3 - Configure your Mac's environment

You will then want to configure your environmental variables and leave PyEnv to manage your packages.

echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

You can activate your changes by running.

source ~/.bash_profile

Step 4 - Install a version of Python

Install Python 3.x.x.

pyenv install 3.5.0

Step 5 - Install another version of Python

Install another version of Python

pyenv install 3.7.0

Step 6 - See all available versions of Python

If you want to list all of the available versions of Python, try:

pyenv install -l | grep -ow [0-9].[0-9].[0-9]

Step 7 - Set your working version of Python

See which versions of Python are installed.

pyenv versions

Set a specific version of Python as your local version.

pyenv local 3.x.x

Set Python version globally.

pyenv global 3.x.x

Double-check your version.

python -V

Resources