The Founder’s Guide:

How to Install the Python Environment for AI and Machine Learning on Mac

The expanded tutorial with concise explanations and screenshots

David Littlefield
Mac O’Clock

--

Image by Caleb Rogers

“The condensed version of this article uses copy and paste code to help you get the outcome ASAP ⚡”

Open Terminal:

The Terminal is a program that’s included with macOS that provides users with access to the operating system using a command-line interface. It uses Z shell by default which replaced Bourne Again Shell as the system shell. It can also work with other shells like Korn, Tenex C, and Bourne Again Shell.

  1. Press “Command ⌘ + Spacebar”
  2. Enter “Terminal”
  3. Press “Return”

Open the Home Directory:

The Change Directory (cd) command is used to change the current working directory to the specified directory. It can navigate to absolute and relative paths that start from the root and current working directory, respectively. It can also navigate to paths stored in variables and environment variables.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
cd $HOME/desktop

Set the Default Version for the Computer:

The Global command is used in Pyenv to specify the default Python version for the entire system. It creates a text file in the Pyenv directory that stores the specified version. This is used by Pyenv to activate the default version but it gets overwritten by the local Pyenv text file and environment variable.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
Python 3.5:
pyenv global 3.5.4
Python 3.6:
pyenv global 3.6.8
Python 3.7:
pyenv global 3.7.9
Python 3.8:
pyenv global 3.8.6
Python 3.9:
pyenv global 3.9.0

Create the Virtual Environment:

The Virtual Environment is an isolated Python installation directory that has its own interpreter, site-packages, and scripts. It mostly gets used to prevent version conflicts between dependencies from different projects. It also gets used to meet dependency requirements of different programs from GitHub.

  1. Find the Python version from below these instructions
  2. Copy the provided command
  3. Paste the command into Terminal
  4. Press “Return”
Python 3.5:
python -m venv venv35
Python 3.6:
python -m venv venv36
Python 3.7:
python -m venv venv37
Python 3.8:
python -m venv venv38
Python 3.9:
python -m venv venv39

Activate the Virtual Environment:

The Activate script is used to start the virtual environment. It prepends the virtual environment path to the PATH environment variable which sets the new Python interpreter and package manager as the default version. It also sets packages to install in the virtual environment installation directory.

  1. Find the Python version from below these instructions
  2. Copy the provided command
  3. Paste the command into Terminal
  4. Press “Return”
Python 3.5:
source venv35/bin/activate
Python 3.6:
source venv36/bin/activate
Python 3.7:
source venv37/bin/activate
Python 3.8:
source venv38/bin/activate
Python 3.9:
source venv39/bin/activate

Install NumPy:

Numerical Python (NumPy) is a C library that’s used in Python to work with arrays. It provides a multi-dimensional array object that’s up to 50x faster than traditional Python lists. It also includes mathematical functions such as trigonometric, statistical, and algebraic routines to perform on the arrays.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m pip install numpy

Install Pandas:

Python Data Analysis (Pandas) is a Python library that’s used to work with structured data. It provides data structures and operations to manipulate numerical tables and time series. It also includes utilities that range from parsing multiple file formats to converting data tables into NumPy arrays.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m pip install pandas

Install SciPy:

Scientific Python (SciPy) is a Python library that’s used to perform numerical computations in mathematics, science, and engineering. It provides a range of commands to manipulate and visualize multi-dimensional arrays. It also includes numerical routines like numerical integration and optimization.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m pip install scipy

Install Pillow:

Pillow is a Python library that’s used to manipulate images in the Python interpreter. It enables Python to open, manipulate, and save images in most image file formats. It also has image processing capabilities such as resizing, cropping, rotating, greyscaling, transforming, and adding text to images.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m pip install pillow

Install Matplotlib:

Matplotlib is a Python library that’s used to create static, animated, and interactive visualizations. It produces production-quality graphs, charts, and figures in a variety of formats. It can also be used in Python scripts, shells, web application servers, and graphical user interface toolkits.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m pip install matplotlib

Install OpenCV:

Open Source Computer Vision Library (OpenCV) is a C++ library that’s used in Python to build real-time computer vision applications. It performs image processing, video capture and analysis, face detection, and object detection. It also has over 2,500 algorithms that range from classic to state of the art.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m pip install opencv-python

Install Scikit-Learn:

Scikit-Learn is a Python library that’s used to build train, and deploy machine learning models for prototyping. It provides algorithms for regression, clustering, and classification. It also includes utilities for preprocessing data, model fitting, and model selection and evaluation.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m pip install scikit-learn

Install Keras:

Keras is a Python library that’s used to rapidly build, train, and deploy deep learning models for prototyping and production. It runs on TensorFlow and offers a user-friendly interface that’s fast, efficient, modular, and easy to use. It was also adopted as the official high-level interface for TensorFlow.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m pip install keras

Install TensorFlow:

TensorFlow is a C++ library that’s used in Python to build, train, and deploy deep learning models for production. It offers fast-performance, scalability, and visualization tools to help examine its data flow graphs. It also supports multiple languages, programming styles, and deploys on most platforms.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m pip install tensorflow

Install PyTorch:

PyTorch is a C++ library that’s used in Python to build, train, and deploy deep learning models for prototyping. It offers high-performance, usability, and flexibility. It was also optimized for Python which led to better memory and optimizations, error messages, model structure, and model behavior.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m pip install torch torchvision torchaudio

Install MxNet:

MXNet is a C++ library that’s used in Python to build, train, and deploy deep learning models for prototyping and production. It offers very high-performance, scalability, usability, and resource efficiency. It also supports multiple languages, programming styles, and deploys on most platforms.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m pip install mxnet

“Hopefully, this article helped you get the 👯‍♀️🏆👯‍♀️, remember to subscribe to get more content 🏅”

Next Steps:

This article is part of a mini-series that helps readers set up everything they need to start learning about artificial intelligence, machine learning, deep learning, and or data science. It includes articles that contain instructions with copy and paste code and screenshots to help readers get the outcome as soon as possible. It also includes articles that contain instructions with explanations and screenshots to help readers learn about what’s happening.

Linux:
01. Install and Manage Multiple Python Versions
02. Install the NVIDIA CUDA Driver, Toolkit, cuDNN, and TensorRT
03. Install the Jupyter Notebook Server
04. Install Virtual Environments in Jupyter Notebook
05. Install the Python Environment for AI and Machine Learning
WSL2:
01. Install Windows Subsystem for Linux 2
02. Install and Manage Multiple Python Versions
03. Install the NVIDIA CUDA Driver, Toolkit, cuDNN, and TensorRT
04. Install the Jupyter Notebook Server
05. Install Virtual Environments in Jupyter Notebook
06. Install the Python Environment for AI and Machine Learning
07. Install Ubuntu Desktop With a Graphical User Interface (Bonus)
Windows 10:
01. Install and Manage Multiple Python Versions
02. Install the NVIDIA CUDA Driver, Toolkit, cuDNN, and TensorRT
03. Install the Jupyter Notebook Server
04. Install Virtual Environments in Jupyter Notebook
05. Install the Python Environment for AI and Machine Learning
Mac:
01. Install and Manage Multiple Python Versions
02. Install the Jupyter Notebook Server
03. Install Virtual Environments in Jupyter Notebook
04. Install the Python Environment for AI and Machine Learning

Glossary:

The Shell is an interpreter that presents the command-line interface to users and allows them to interact with the kernel. It lets them control the system using commands entered from a keyboard. It also translates the commands from the programming language into the machine language for the kernel.
[Return]

The Interpreter is a program that reads through instructions that are written in human readable programming languages and executes the instructions from top to bottom. It translates each instruction to a machine language the hardware can understand, executes it, and proceeds to the next instruction.
[Return]

The Command-Line Interface (CLI) is a program that accepts text input from the user to run commands on the operating system. It lets them configure the system, install software, and access features that aren’t available in the graphical user interface. It also gets referred to as the terminal or console.
[Return]

The Kernel is the program at the heart of the operating system that controls everything in the computer. It facilitates the memory management, process management, disk management, and task management. It also facilitates communication between the programs and hardware in machine language.
[Return]

The Variable is the container that’s used to store different types of values. It can assign or update a value by placing an equals sign between the specified variable name and value without a space around it. It can also reference the stored value by placing a dollar sign in front of the existing variable name.
[Return]

The Environment Variable is a variable that’s automatically created and maintained by the computer. It helps the system know where to install files, find programs, and check for user and system settings. It can also be used by graphical and command-line programs from anywhere on the computer.
[Return]

The Site-Packages is a directory that’s located in the system-wide Python installation directory. It represents the default location that package managers use to install Python packages. It also represents the directory that Python uses to import Python packages that are already installed.
[Return]

The Dependency is an additional binary package that a particular binary package needs to work properly. It can require multiple dependencies to build almost any program that’s distributed by package managers. It also gets downloaded and installed automatically by some package managers.
[Return]

The PATH is an environment variable that contains the list of directories the computer uses to find executable files. It looks for the requested executable file in each directory on the list from top to bottom. It also stops searching once it finds a matching executable file and runs the program or command.
[Return]

The Binary Package is an archive file that contains the files and directories needed to make its containing program work properly. It gets stored in the repository that contains all the programs for a specific Linux distribution. It also requires the Linux package manager to access, extract, and install it.
[Return]

The Data Flow Graph is used in TensorFlow to describe computations in the language of graph theory. It defines the sequence of computations that are performed using a directed graph of nodes and edges. It also uses the nodes to represent mathematical operations and the edges to connect the nodes which allows data to flow from one node to another in a directed manner.
[Return]

The Node is used in TensorFlow to represent a mathematical operation in the data flow graph. It references the computation of the operation but it only produces an actual value when the graph is executed. It can also take input from any number of previous nodes, perform the computation, and generate a single output that can be passed as the input to another node.
[Return]

The Edge is used in TensorFlow to represent one of the lines that connects the different nodes in the data flow graph. It references the data in tensors that flows through the different operations in the graph. It also carries the information from one node to another where the output of one operation becomes the input to another and the edge between them carries the value.
[Return]

The Tensor is a data structure that’s used in machine learning to represent the inputs, outputs, and transformations for all data types within neural networking. It generalizes concepts from mathematics and programming like scalars, vectors, matrices and numbers, arrays, and two-dimensional arrays into multidimensional arrays that range from zero to n-dimensions.
[Return]

--

--

David Littlefield
Mac O’Clock

From: Non-Technical | To: Technical Founder | Writes: To Make It Easier For Everyone | Topics: #Startups #How-To #Coding #AI #Machine Learning #Deep Learning