DigitalOcean Referral Badge
Udit Vashisht
Author: Udit Vashisht

How to install Python 3 on MacOS and Linux?

MacOS व Linux पर Python 3 इंस्टॉल कैसे करें?

  • 4 minutes read
How to install Python 3 on MacOS and Linux?

    Table of Contents

In this post, we will learn the various ways of installing Python 3 on MacOS or Linux.

Installing on MacOS
MacOS X and above comes with the legacy version of Python i.e. Python 2.7 out of the box. This can be checked by adding the following code in terminal:-

$ python -V
Python 2.7

But that is an old version and we will be using the following ways to install the latest stable version of Python 3.7:-

1. Using the dmg Installer

Open and this will automatically detect your OS and show you an option to download the latest stable version of Python 3.7, which at the time of writing this blog is 3.7.2.


Double click the downloaded file and follow the steps to install Python 3.7.2.

Once finished you can check for the version installed using the following code in terminal:-

$ python3 -V
Python 3.7.2

You need to remember two things here:-

  1. Every time you need to use Python 3 u need to use ‘python3’ instead of ‘python’ because ‘python’ by default will run Python 2.7. There are ways to change it but that needs another post and we will come up with that soon.
  2. -V is in uppercase, we can also use ‘–version’.

Once, you are done you can check for pip using the following code, if it runs without an error, then you are good to go:-

pip3 freeze


pip freeze

Alternatively, you can install pip3 using the following command:-

$ sudo easy_install pip3

Watch the video Tutorial

You can also watch the following video too:-

2. Using the HomeBrew
This is the way which hard-core programmer prefer and it is also called the right way to install Python3.

Before installing Python 3 using this method, you will need GCC. The easiest way to install the same is by installing xcode by typing the following in the terminal:-

$ xcode-select --install

Once, you are done installing it, install homebrew using the following command:-

$ ruby -e "$(curl -fsSL"

Once, you are done you need to add PATH in your bash profile, this can be done by going to the home directory using ‘cd’ and then opening the ‘.bash_profile’ using some editor like nano

$ cd
$ sudo nano .bash_profile

This will open your ‘.bash_profile’ now at the very bottom add the following line:-

export PATH="/usr/local/opt/python/libexec/bin:$PATH"


export PATH=/usr/local/bin:/usr/local/sbin:$PATH (If you are using MacOS Sierra or higher)

Now, the last command will install the latest stable version of Python 3 for you:-

$ brew install python

Check the installation of Python and pip using the commands described in the first method.

One of the advantages of installing the homebrew version of python is, you can easily update it using a simple command:-

$ brew upgrade python

Watch the video Tutorial

You can also watch the following video too:-

Installing on Linux

Ubuntu 16.10 or later version

Use the following command in your terminal/bash

$ sudo apt-get update
$ sudo apt-get install python3.7

Other versions of Ubuntu e.g. LTS release

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.7

You can check for version installed and pip as under:-

$ python3 -V 
$ python3 --version
$ command -v pip3

If pip3 is not installed follow the instructions here

One thing you need to note that your MacOS or Linux may have an older version of python installed in it if python -V shows Python 2.7 instead of Python 3.7.2, you need to use python3 and pip3 to run the latest version of Python.

Related Posts

How to install selenium on Macbook Pro/Macbook Air?
By Udit Vashisht

How to install Selenium on Macbook Pro/Macbook Air?

In this tutorial we will learn, how to install selenium on all Mac devices like iMac, Macbook Pro, Mac Mini, Macbook Air with intel or M1/M1 Pro/ M1 Max chipset.

Install Selenium using pip

  1. First of all you need to ...

    Read More
How to install Python3 on Windows PC?
By Udit Vashisht

In this Post we will be learning how to install python on our Windows PC. First of all we need to be sure whether we are using 32-bit system or 64-bit. To find it out, right click on ‘This PC’ icon on your desktop and click ‘properties’, there you will ...

Read More
tech tutorials automate python beautifulsoup web scrapping webscrapping bs4 Strip Python3 programming Pythonanywhere free Online Hosting hindi til github today i learned Windows Installations Installation Learn Python in Hindi Python Tutorials Beginners macos installation guide linux SaralGyaan Saral Gyaan json in python JSON to CSV Convert json to csv python in hindi convert json csv in python remove background python mini projects background removal tweepy Django Django tutorials Django for beginners Django Free tutorials Proxy Models User Models AbstractUser UserModel convert json to csv python json to csv python Variables Python cheats Quick tips == and is f string in python f-strings pep-498 formatting in python python f string smtplib python send email with attachment python send email automated emails python python send email gmail automated email sending passwords secrets environment variables if name == main Matplotlib tutorial Matplotlib lists pandas Scatter Plot Time Series Data Live plots Matplotlib Subplots Matplotlib Candlesticks plots Tutorial Logging unittest testing python test Object Oriented Programming Python OOP Database Database Migration Python 3.8 Walrus Operator Data Analysis Pandas Dataframe Pandas Series Dataframe index pandas index python pandas tutorial python pandas python pandas dataframe python f-strings padding how to flatten a nested json nested json to csv json to csv python pandas Pandas Tutorial insert rows pandas pandas append list line charts line plots in python Django proxy user model django custom user model django user model matplotlib marker size pytplot legends scatter plot python pandas python virtual environment virtualenv venv python python venv virtual environment in python python decorators bioinformatics fastafiles Fasta python list append append raspberry pi editor cron crontab Cowin Cowin api python dictionary Python basics dictionary python list list ios development listview navigationview swiftui ios mvvm swift environmentobject property wrapper @State @Environm popup @State ios15 alert automation instagram instaloader texteditor youtubeshorts textfield multi-line star rating reusable swift selenium selenium driver requests-html youtube youtube shorts python automation python tutorial algo trading nifty 50 nifty50 stock list nifty50 telegram telegram bot dictionary in Python how to learn python learn python