Learn To Setup Python 3 As A Default On your Mac
Tags: python, beginners, productivity, webdev
Published: 2020-09-26 06:34:25

## Minimum requirements

- Command Line tools or Xcode
`$ xcode-select --instal`
-  [Homebrew](https://brew.sh/)
`$ ruby -e "$(curl -fsSL [https://raw.githubusercontent.com/Homebrew/install/master/install](https://raw.githubusercontent.com/Homebrew/install/master/install))"`

## Python3

At the time of this writing your Macbook ships with an out of date version of **[Python](https://www.python.org/download/releases/2.0/)**, **version 2.7** which was officially deprecated on Januray 1st, 2020. This means you need to update it to version 3 before building any new projects in your local development environment. 

```
WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Jul  5 2020, 02:24:03)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.21) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
```



My preferred method of achieving this is to use [Homebrew](https://brew.sh/) a very popular MacOs package manager. This will allow you to switch between [**Python3**](https://www.python.org/downloads/) and **[Python 2](https://www.python.org/download/releases/2.0/)** in case you still need it. Please make sure you have it installed before continuing.

Open your terminal and run the following.

```
$ brew install python
```

To look at where it is installed run this command to get a similar output.

```
$ which python3
/usr/local/bin/python3
```

If you wish to be able to run a command with just **python** instead of **python3** create an alias in your **.zshrc**. Copy the python3 installation path from above and run the following command.

```
$ echo "alias python=/usr/local/bin/python3" >> ~/.zshrc
```

Close your terminal and open it back up. Now if you run the command **python** you should get the following.

```
$ python --version
Python 3.8.5
```



Now if you need **Python 2**  to work on some older projects run it like this.

```
$ python2
```

Aslo If at any time you would like to set **Python 2** as default on your Mac again just remove or comment out the alias in your **.[zshrc](https://www.zsh.org/)** with [vim](https://vim.rtorr.com/) or any editor you like.

```
$ vi ~/.zshrc
```

Edit your **.zshrc**  and comment out the alias.

```
#alias python=/usr/local/bin/python3
```

## Pip

Finally don't forget to update [**pip**](https://pypi.org/project/pip/) to **pip3**. The **pip** command is the default package manager for **Python** packages and although the default version of python on your system was updated pip is still running on the old version. To fix that create another alias for **pip3**. This will ensure the packages installed via pip are compatible with the new default version of **Python**.

First find the location of **pip3**.

```
$ which pip3
/usr/local/bin/pip3
```

 Now create the new alias.

```
$ echo "alias pip=/usr/local/bin/pip3" >> ~/.zshrc 
```

Close your terminal to reset it and run the **pip** command.

```
$ which pip
pip: aliased to /usr/local/bin/pip3
```

That's it! as always if you have any questions, comments or concerns feel free to reach out to me on [Twitter](https://twitter.com/jQNReactor).

Best.