Tech
Mar 15, 2024

How to Install Python on macOS a quick and easy guide

Python and macOS, here's a quick guide to get your coding going.

Python is a versatile and popular programming language used for web development, data analysis, artificial intelligence, and more. Installing Python on macOS is a straightforward process, and this guide will walk you through the steps.

Step 1: Check Python Version (Optional)

macOS typically comes with Python pre-installed. To check the version, open the Terminal app (you can find it in Applications -> Utilities) and type:

This will display the version of Python installed on your system. If you see a version like Python 2.x, you may want to install Python 3, which is the latest version and recommended for most users.

Step 2: Install Homebrew (Optional)

Homebrew is a package manager for macOS that makes it easy to install software packages. If you don't have Homebrew installed, you can do so by running the following command in the Terminal:

Follow the on-screen instructions to complete the installation.

Step 3: Install Python 3

To install Python 3 using Homebrew, run the following command in the Terminal:

This will download and install Python 3 and its dependencies. After the installation is complete, you can verify the installation by typing:

This should display the version of Python 3 installed on your system.

Step 4: Verify Installation and Set PATH (Optional)

To make sure that the 'python3' command is available in your Terminal, you can add it to your PATH.

open your shell config file ( '.bash','.bash_profile', or '.zshrc, depending on your shell) in a text editor

and add the following line:

Save the file and then source it to apply the changes:

You should now be able to use the 'python3' command in your Terminal to run Python 3 scripts.

Step 5: Install Pip (Python Package Installer)

Pip is a package manager for Python that allows you to install third-party libraries and packages. To install Pip for Python 3, run the following command:

Conclusion

You have successfully installed Python 3 on your macOS system. You can now start using Python for your development projects. If you encounter any issues during the installation process, refer to the official Python documentation or seek help from online forums and communities.