How to Install Python on Mac?

Today you will learn various methods for installing Python on Mac operating system. Alternatively, you can install Python on a Windows or Linux  OS.

Python is among the most potent and easy programming language and is primarily utilized in data science, machine learning, and big data analytics.

Hence, Installing Python is therefore required. As a beginner developer, you may need help correctly updating or installing Python on your Mac Devices.



Installing Python On Mac

When we talk about install Python on Mac, you must install the latest Python alongside the built-in version on Mac OS.

All programming languages have improved by adding various features. Programmers and developers announce these improvements and changes by releasing new versions.

If you want to know what version of Python you already have configured, you can launch the Terminal application by typing command+space and spelling out the terminal. Then press return. You can now verify that Python 2.7 is preinstalled on your Mac by typing the following command:

% python --version
Python 2.7.18

Using the following command, you can determine whether Python 3 is installed on your Mac:

~ % python3 --version

Terminal will likely display the below message:

xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting installation. Choose an option in the dialog to download the command line developer tools.

Immediately beneath the Terminal window will appear a dialog box stating the command requires command line developer tools. Let’s begin by identifying the command-line developer tools.

In a nutshell, the command line developer tools package includes tools used primarily in development. These programs run various commands, such as make, git, Python 3, etc.

While installing Python 3.x on Mac without configuring the command line developer tools is feasible, Mr Examples recommends configuring them.

Because it offers a wide range of development tools, the package can be installed by clicking the Install button and performing the procedure steps. Upon completion of the installation process, rerun the initial command. Python 3.x has been installed on your Mac.

~ % python3 --version
Python 3.8.9

Download and Install Python:

The easiest and preferred method of installing Python on a Mac is downloading the latest version from the official Python website.

  • First, download a Python installer package from the link mentioned above.
  • Double-click the Python package after downloading is complete to begin the installation. The installer walks you through the process with a wizard. You may also need to enter your Mac password to inform Python that you agree with the installation. See screenshot below:

Install Python on Mac OS

REMEMBER: You will need to install Rosetta using an Apple M1 Mac. On Apple silicon Macs, Rosetta allows Intel-based features to run.

  • Upon completion of installation, Python folder will appear on screen automatically same as image below.

python setup completes

  • Make sure Python and IDLE are installed correctly. You can do this by double-clicking IDLE, the Python integrated development environment. The Python shell should appear as image below – in IDLE if your installation is running correctly:

install python on mac terminal

  • Using IDLE, let’s create a basic Python program. Enter the following statement and press return.
print(“Congrats! You can now use python.”)

your first code - python on mac

REMEMBER: With this installation technique, you can quickly upgrade your Python installation by downloading the latest Python installer. Upon completion of the installation, the most recent Python version will be available on your Mac.


Installing Visual Studio Code on Mac

In this article section, we will install Visual Studio Code on Mac operating system to develop Python projects.

Instead of restricted coding environments, we use an efficient, expandable, easy-to-use code IDE when developing Python scripts.

  • The first thing to do is download Visual Studio Code for macOS. See screenshot below for same

Download visual studio for mac

  • To extract the archived contents, click twice on the .zip file. See Image below:

Extract vscode zip file

  • To make Visual Studio Code available in the macOS launchpad – move it to the Application folder. Check out the image below for the same:

vscode application folder path

  • Open the Python scripts folder in Visual Studio Code (or create one from scratch).

Steps:

  1. Create a folder on your desktop named py_scripts, then open the folder in Visual Studio Code.
  2. Your Desktop folder usually needs the approval to be accessed by VS Code; click OK to allow.

VScode access notification on mac

3. Additionally, you are likely to indicate your trust in the authors of the files stored in your Desktop folder.

mac trust setting for VScode

  • Make a new file ending with .py extension. For instance, call it pythonprogram.py. VS Code detects the Python extension, so you must install it.

It is necessary to use the Python extension in VS Code to work with Python. The Python extension includes many valuable features, including code completion, debugging, and unit testing.

  • Click on the Install button to install it.

installing python extensions on mac os

 

Browsing extensions can also install the Python extension. In VS Code, choose Extensions from the left-hand menu.

python extension icon on mac

You can find a collection of the most popular VS Code extensions on the VS Code Marketplace. Once we have selected the Python extension, we can install it.

python extension list on mac

  • You need to pick a Python interpreter after installing the extension. Select a Python interpreter by clicking the button:

how to select python interepter on mac

  • On the list, choose the Python interpreter that is best for you. Using the latest Python version on your Mac is more convenient if you have more than one Python version installed.

python interepter latest version on mac

A Python interpreter can also be picked using the Python:

  1. Select Interpreter command from the Command Palette.
  2. Select an interpreter by pressing CMD + SHIFT + P, typing Python, and choosing Python.

First Python Code On Mac

Fantastic, all we need for Python code writing is in VS Code. Let’s run the following code in VS Code.

print("Hello, World!)
name = input("What's your name? ")
print("Hello {}!\nWelcome to Dataquest!".format(name))

On VS Code, click the Run button at the top right corner. It starts with Hello, World! In the integrated terminal, When you hit return, you are asked to enter your name. It prints Hello <your name>, and then Welcome to Dataquest! On the following line.


Conclusion

This tutorial taught us how to install Python on Mac and update an outdated Python version. As well as installing Visual Studio Code and configuring it for Python scripting, we learned how to use Python. As a final step, we ran a small Python script in VS Code. How to create and use Python virtual environments will be the topic of the following tutorial.

Best wishes! You can become a great Pythonista from now on!

We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *