Installing Python



This tutorial documents the installation of Python3 on macOS.

Installation described here is based on the popular "Homebrew" package manager for macOS - feel free to use alternative options if you prefer.

1. Install “commandline tools” - execute this command in Terminal app

$ xcode-select --install


2. Install Homebrew, open Terminal App and run

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

The script will guide you and explain what changes it will make and prompt you before the installation begins - you may also be asked to install some other software like git, other development tools during this process.

Note

There are reports of problems with using git on some Mac systems after upgrading from older OS.

This command may help to fix git functionality:

$ sudo xcode-select -switch /Library/Developer/CommandLineTool


3. Once you’ve installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.zprofile file (this is - in case you have default zsh selected for terminal app, you should see version of bash on top of terminal app window):

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

If you have OS X 10.12 (Sierra) or older use this line instead

$ export PATH=/usr/local/bin:/usr/local/sbin:$PATH


4. Now, we can install Python3:

$ brew install python3

This will take a minute or two.

Homebrew installs pip3 pointing to the Homebrew's Python3 for you pip3 is a package manager for Python, which you will use to install additional packages on your system.


5. Check if default command is pointing to correct version:

$ python --version

If not (for example it shows older 2.x version) - you can add this to your configuration.

$ echo "alias python=/opt/homebrew/bin/python3 >> ~/.zshrc"

This will link you python and python3 commands together.

$ python --version

Python 3.10.6

$ python3 --version

Python 3.10.6


6. Official Python installation:

Note

You can also use "official" Python installation link - it may require some extra steps to be done on your system depending on the operational system and existing configuration:

https://www.python.org/downloads/



Post a Comment

Previous Post Next Post