Setting up Python for Machine Learning course work

Tristian Azuara
2 min readFeb 8, 2021

--

Simple, short guide to setup Python and some Machine Learning libraries in a macOS computer.

Pyenv

We will be using pyenv to manage python versions, macOS by default comes with python2.7 installed, however you should not modify or use that version because it is mostly used for OS or low level system management and the OS expects for it to be always available. Instead we will use a CLI tool called Pyenv to install the desired python version

First make sure that you have homebrew installed:

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

Install pyenv using homebrew:

brew update && brew install pyenv

Then update your .bashrc or .zshrc file to include the path of pyenv, run the following in a terminal:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"'

Then restart your shell by running the following:

exec "$SHELL"

Installing a specific python version

Run the following in a terminal; which will install Python 3.8.5

pyenv install 3.8.5

Installing common ML libraries

First make sure that you have the recently installed python version (3.8.5)

python --version
# Python 3.8.5

And also make sure that pip (the python package manager) points to the location of the same version:

pip --version
# pip 20.1.1 from /Users/tristian/.pyenv/versions/3.8.5/lib/python3.8/site-packages/pip (python 3.8)

Finally upgrade pip to the latest version:

pip install --upgrade pip

Install the libraries

We will be installing the following libraries:

  • Scikit-Learn
  • Pandas
  • Numpy
  • Matplotlib
  • Seaborn
  • Jupyter

They can all be installed with the single following command in a terminal:

pip install -U scikit-learn pandas numpy matplotlib seaborn jupyter

The command might take a bit but after it finishes you should be ready to start ML’ing away!

--

--

Tristian Azuara

iOS Engineer with a love for automation and internal tooling. Gopher, Pythonista and Haskeller by night. https://www.linkedin.com/in/aztristian/