ProductizeML
  • ProductizeML
  • Introduction
    • Objectives
    • About the Course
    • Guidelines
    • Syllabus
    • After Completion
  • Machine Learning
    • Why ML, and why now
    • Supervised Learning
    • Unsupervised Learning
    • Deep Learning
    • ML Terminology
  • Data Management
    • Data Access
    • Data Collection
    • Data Curation
  • Train and Evaluate
    • Framework and Hardware
    • Training Neural Networks
    • Model Evaluation
  • Productize It
    • ML Life Cycle
    • Business Objectives
    • Data Preparation
    • Model Development
    • Train, Evaluate, and Deploy
    • A/B Testing
    • KPI Evaluation
    • PM Terminology
  • Resources
    • Readings
    • Courses
    • Videos
  • Hands-On
    • Python for Machine Learning
      • Python Installation
        • MacOS
        • Linux
Powered by GitBook
On this page

Was this helpful?

  1. Hands-On
  2. Python for Machine Learning
  3. Python Installation

MacOS

Install Python in MacOS systems

PreviousPython InstallationNextLinux

Last updated 2 years ago

Was this helpful?

To follow this guide, you will need to install first.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

After Homebrew is installed, let's install pyenv:

brew update
brew install pyenv

This command will show a list of Python versions:

pyenv install --list

Now let's install the latest Python version (3.8.5 as of this writing):

pyenv install 3.8.5

Now that Python 3 is installed through pyenv, we want to set it as our global default version for pyenv environments:

$ pyenv global 3.8.5
# and verify it worked
$ pyenv version

The power of pyenv comes from its control over our shell's path. In order for it to work correctly, we need to add the following to our configuration file (.zshrc or .bash_profile) depending on your terminal version:

$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

Now create a new terminal session and run:

python -V

You should see the 3.8.5 version showing up.

Sources:

Homebrew
https://brew.sh/
https://github.com/pyenv/pyenv
https://opensource.com/article/19/5/python-3-default-mac