How to Install Python on Mac — Python Tutorial

Introduction

Python is a high-level, dynamic, general-purpose language. It was developed by Guido Van Rossum in 1991. Python’s syntax allows developers to use fewer lines of code than any other programming language. It basically focuses on the code readability of program. Python 2.7 is installed by default on MacOS but we can install other versions like python 3.5 and 3.6.

In this tutorial, we are learning how to install Python 3.6.3 on the MAC Operating system.

Prerequisites

  • MacOS
  • Login as an administrator on terminal

Installation

There are following steps which are used while installing Python3 on MacOS.

1) Checking python’s version on the system

We can check which version of the Python is currently installed on our system. Generally, Python 2.7 is installed by default.

Let’s see how can we do it.

$ python -version   

It shows Python 2.7.10 is installed on the computer, which happens quite often.

2) Download Python 3.6.3

In order to install Python 3.6.3, we must download the latest version from its official website, https://www.python.org/downloads/ . The file is downloaded in .pkg format which can be directly installed by using Installer command.

3) Install Python 3.6.3

Since the downloaded file is already in.pkg format, no mounting is required, and we can use the installer command to install Python 3.6.3.

Let’s see how we can do it.

Since The installer is used with super user permissions hence sudo forces terminal to prompt the user to fill the admin password. The process installs Python 3.6.3 to the root directory, which is mentioned with the target option.

4) Verify Python3

To check which Python version is installed on the machine, we can use the python --version command. Since the default installed version is Python 2.7.10, it shows Python 2.7.10. but it gives us flexibility to check the version of Python 3 on our computer.

Let’s see how we can use Python 3 to check which version of Python 3 is running.

$ python -version  

5) Working on Python’s script mode

To work on the Python command line, we simply type python3 on the terminal. Python shell open where we can run Python statements such as print statements as we did here.

To run a Python file (.py) on the terminal, we simply type the file name, and the file will be interpreted.

Well, we have installed Python3 on our MacOS.

--

--

Rajguleria
Python Tutorial | Python Programming Language

help 9-5 workers start a one-person business without quitting their jobs. Start building your 1-person biz here -> https://michaellim.ck.page/crashcourse 🚀