avatarDavid Littlefield

Summary

This web content provides a comprehensive guide for installing and managing multiple Python versions on a Mac using Homebrew and Pyenv, along with instructions for setting up virtual environments.

Abstract

The article titled "THE FOUNDER’S GUIDE:" is an extensive tutorial aimed at Mac users who wish to install and manage multiple versions of Python on their systems. It begins by instructing users on how to access the Terminal, a command-line interface in macOS, and then guides them through checking the default Python version and locating the Python executable file. The tutorial emphasizes the use of Homebrew, a package manager for macOS, to install Pyenv, which is a tool for managing multiple Python versions. It also covers the installation of necessary dependencies for Pyenv and the process of installing specific Python versions. The guide further explains how to set the default Python version globally and locally, as well as how to create and manage virtual environments for different projects. Throughout the tutorial, the author provides screenshots and concise explanations to facilitate understanding and execution of the steps. The article concludes with a glossary of terms and a roadmap for further learning in artificial intelligence, machine learning, and data science.

Opinions

  • The author believes in the importance of using package managers like Homebrew for efficient software management.
  • There is an emphasis on the flexibility provided by Pyenv for users to switch between Python versions as needed.
  • The guide is designed to be accessible to users with varying levels of technical expertise by providing clear instructions and visual aids.
  • The author suggests that managing Python versions is crucial for avoiding version conflicts and ensuring compatibility with different projects.
  • The article promotes the use of virtual environments as a best practice for Python development to isolate project dependencies.
  • The author encourages readers to subscribe for more content, indicating a commitment to ongoing education in the fields of AI, machine learning, and data science.

THE FOUNDER’S GUIDE:

How to Install and Manage Multiple Python Versions on Mac

The expanded tutorial with concise explanations and screenshots

Image by Isabella and Louisa Fischer

“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”

Check the Default Version:

The Version (V) option is used to check which version of Python is currently selected as the default version. It consists of three numbers separated by periods that represent the major, minor, and micro version number. It also displays an error message if Python isn’t already installed on the computer.

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

Check the Executable File:

The Which command is used to identify the location of the executable file for the specified command name. It searches for the executable file in the list of directories from the PATH environment variable. It also displays the absolute path of the executable file if it exists in the one of the directories.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
which python

Install Homebrew:

Homebrew is a package manager that provides access to thousands of programs on macOS. It manages the entire installation process which includes downloading, compiling source code, moving files, installing dependencies, creating symbolic links, and deleting installation files.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install Pyenv:

Pyenv is a program that’s used for Python version management on macOS and Linux. It can install multiple Python versions, specify the version that’s used system-wide, and specify the version that’s used in specific directories. It can also create and manage virtual environments using specific versions.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
brew install pyenv

Install the Pyenv Dependencies:

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.

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
brew install openssl readline sqlite3 xz zlib

View the Python Versions:

The List (l) flag is used to display the Python versions that are available in Pyenv. It includes final versions that are released from Python, Anaconda, PyPy, Jython, and Stackless. This includes all the major, minor, and micro versions but it doesn’t include alpha, beta, or release candidate versions.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
pyenv install --list

Install Python:

Python is an object-oriented language that’s known for its simple syntax, code readability, flexibility, and scalability. It mostly gets used to develop web and software applications. It also has become one of the most popular languages for artificial intelligence, machine learning, and data science.

  1. Find the version from below these instructions
  2. Copy the provided command
  3. Paste the command into Terminal
  4. Press “Return”
  5. Repeat
Python 3.5:
pyenv install 3.5.4
Python 3.6:
pyenv install 3.6.8
Python 3.7:
pyenv install 3.7.9
Python 3.8:
pyenv install 3.8.6
Python 3.9:
pyenv install 3.9.0

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”
pyenv global 3.8.6

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 ~

Create the Zsh Configuration File:

The Echo command is used to print text it receives from the argument to the screen or to a computer file. It can be used in shell scripts and batch files to print the output of other commands or as part of other commands to insert text. It can also overwrite the text in an existing file or append it at the end.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
echo "" >> .zshrc

Open the Zsh Configuration File:

The Shell Configuration File is a script that’s automatically executed when a shell is opened by the user. It contains code that’s used to change the look of the shell, run scripts and commands, create aliases, and load environment variables. It also creates a separate configuration file for the different shells.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
open -a textedit ~/.zshrc

Edit the Zsh Configuration File:

Z Shell (Zsh) is an interactive shell that’s used as a login shell and command interpreter for shell scripting. It provides an extended version of Bourne Again Shell which contains features from Bourne Again Shell, Korn, and Tenex C. It also includes many original features like plugins and themes.

  1. Copy the code from below these instructions
  2. Paste the code into TextEdit
  3. Click the “File” menu
  4. Click “Save”
# Pyenv initialization
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

Restart Zsh:

The Exec (e) command is used to execute the specified command that’s provided as an argument. It destroys the current process and replaces it with the specified command without creating a new process. It can also restart the shell to reload the configuration file into the environment.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
exec zsh

Create the Temporary Directory:

The Make Directory (mkdir) command is used to create new directories. It can specify one or more relative or absolute paths with the name of the new directories to be created. It can also be used with the “Parents” flag to create parent directories as needed without overwriting a path that already exists.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
mkdir temporary

Open the Temporary 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 temporary

Set the Default Version for the Directory:

The Local command is used in Pyenv to specify the default Python version for the current directory. It creates a text file in the current directory that stores the specified version. This is automatically detected by Pyenv which activates the Python version in the current directory and subdirectories.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
pyenv local 3.6.8

Check the Default Version:

The Version (V) option is used to check which version of Python is currently selected as the default version. It consists of three numbers separated by periods that represent the major, minor, and micro version number. It also displays an error message if Python isn’t already installed on the computer.

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

Open the Parent 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 ..

Check the Default Version:

The Version (V) option is used to check which version of Python is currently selected as the default version. It consists of three numbers separated by periods that represent the major, minor, and micro version number. It also displays an error message if Python isn’t already installed on the computer.

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

Open the Temporary 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 temporary

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. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
python -m venv venv36

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. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
source ./venv36/bin/activate

Check the Default Version:

The Version (V) option is used to check which version of Python is currently selected as the default version. It consists of three numbers separated by periods that represent the major, minor, and micro version number. It also displays an error message if Python isn’t already installed on the computer.

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

Check the Executable File:

The Which command is used to identify the location of the executable file for the specified command name. It searches for the executable file in the list of directories from the PATH environment variable. It also displays the absolute path of the executable file if it exists in the one of the directories.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
which python

Deactivate the Virtual Environment:

The Deactivate command is used to stop the virtual environment. It removes the virtual environment path from the PATH environment variable which sets the last Python interpreter and package manager as the default version. It also sets packages to install in the system Python installation directory.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
deactivate

“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 Major version is a number that represents an update that introduces significant changes to a program. It can add different architecture, features, and functionality that’s incompatible with previous versions. This usually causes programs that were built with a previous version to stop working. [Return]

The Minor version is a number that represents an update that introduces moderate changes to a program. It can add small features and functionality that’s compatible with the latest major update. This usually doesn’t cause problems with programs that were built with the previous minor updates. [Return]

The Micro version is a number that represents an update that introduces very modest changes to a program. It can add bug fixes and performance enhancements that are compatible with the previous updates. This doesn’t cause problems with programs that were built with the previous updates. [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 Executable File (exe) is a file format that’s used to run programs and scripts once it’s opened. It performs a task or group of tasks according to the source code or instructions that are contained in the program or script. It can also contain viruses based on whether it came from a trusted source. [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 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]

Data Science
Artificial Intelligence
Machine Learning
Technology
Programming
Recommended from ReadMedium