Installing Python on macOS

If you open a terminal and type python at the prompt, you will see that the system version is Python 2 (Figure 2-2). Django is not compatible with Python 2, so we need to install the latest version of Python 3.

Installing Python on macOS - 图1

Figure 2-2: macOS uses Python 2, which is incompatible with Django.

Downloading a copy of Python 3 follows the same process as Windows—Go to https://www.python.org/downloads/ and click the big yellow button that says “Download Python 3.x.x”. Your browser should automatically detect that you are using macOS and take you to the correct download page. If it doesn’t, select the correct operating system from the links below the button.

The Mac installer is in .pkg format, so once it’s downloaded, double-click the file to run the package installer (Figure 2-3). The screenshot is for Python 3.7, but the process is identical for Python 3.8.

Installing Python on macOS - 图2

Figure 2-3: Follow the prompts to install Python 3 on macOS.

Follow the installations steps and, when Python 3 has been installed, open a new terminal window. If the installation was successful, typing python3 at the prompt will open the Python 3 interactive shell (Figure 2-4). Note that macOS will happily run multiple versions of Python on the one machine, you just need to make sure you select the correct version when running the terminal.

Installing Python on macOS - 图3

Figure 2-4: Once Python 3 is installed, run it from the terminal with the python3 command.