Installing Python on MacOS

Download PDF

1. Installing Python

Installing Python on your computer allows you to run Python code. Python is an interpreted high-level programming language with simple syntax.

You can install Python on MacOS by following these steps:

  1. Go to the following link to download the installer: Python Download for MacOS
  2. Click the latest Python 3 release.
  3. Scroll down to the files section at the bottom.
  4. If you have a Mac with an Intel processor, click macOS 64-bit Intel installer and save the file. If you have a Mac with Apple Silicon, click macOS 64-bit universal2 installer and save the file. If you are unsure which processor your Mac has, check this guide.
  5. Once downloaded, run the installer.
  6. Click Continue and Agree.
  7. Click Install.
  8. Enter your password or use Touch ID if prompted.
  9. Wait until you see the "Setup was successful" screen, then click Close.

You have successfully installed Python on your computer. To open IDLE, search for "IDLE" in Spotlight search or find it in Launchpad. To open IDLE from the terminal, type:

idle3

2. Changing IDLE's Default Behavior

By default, IDLE opens in the Shell window, which allows you to run Python commands interactively, but does not provide an interface for writing longer scripts efficiently.

What is the IDLE Shell Window?

When IDLE is launched, it usually opens in the Shell window by default. The Shell window allows you to type and execute Python commands interactively. However, it is not ideal for writing longer scripts, as it does not allow saving or editing multiple lines of code easily.

How to Open the Edit Window by Default

To make IDLE open in the Edit window each time, follow these steps:

  1. Open IDLE.
  2. Go to the menu bar and click IDLE (on the top-left of the screen).
  3. Select Preferences... (under IDLE on MacOS).
  4. In the Windows tab, look for the option Open Edit Window under the "At Startup" section.
  5. Check the box next to it.
  6. Click Apply and OK to save your changes.

Now, every time you launch IDLE, it will open in the Edit window where you can write and save scripts easily.

If you prefer opening the Edit window manually, you can do so by:

This will allow you to start writing and saving Python scripts with ease.

3. Installing Command Line Tools (CLT)

Command Line Tools for Xcode are essential for compiling and running development tools, including Python. They provide UNIX command-line utilities such as gcc, git, and make, which are needed to run Python in Visual Studio Code.

Installation Steps:

  1. Open the Terminal by searching for "Terminal" in Spotlight.
  2. Type the following command and press Enter:
xcode-select --install
  1. A pop-up will appear asking you to install the tools. Click Install.
  2. Wait for the installation to complete.
  3. Verify the installation by typing:
xcode-select --version

If you see a version number displayed, the installation was successful.

4. Installing Packages

Installing packages allows you to use code written by others. You can install them by following these steps:

  1. Search for "Terminal" in Spotlight search and open it.
  2. Install Python packages using the following command:
pip3 install [insert package name(s) here, without the square brackets]

For example, to install all the packages needed for CSCI 127 at Hunter College, type:

pip3 install numpy image matplotlib scipy pandas folium

You have successfully installed Python packages.

4. Installing and Setting Up Visual Studio Code for Python

Visual Studio Code (VS Code) is a popular code editor with features that enhance Python development. Follow these steps to install and set it up:

Installation Steps:

  1. Go to the official VS Code download page: Download VS Code.
  2. Click the Download for Mac button.
  3. Once downloaded, open the downloaded file and drag the VS Code icon to the Applications folder.
  4. Launch VS Code from Launchpad or Spotlight.

Setting Up Python in VS Code:

  1. Open VS Code.
  2. Go to the Extensions tab on the left sidebar (or press Cmd + Shift + X).
  3. Search for "Python" and install the extension provided by Microsoft.
  4. Once installed, open a new terminal inside VS Code (View > Terminal).
  5. Type
    python3 --version
    to check if Python is recognized.
  6. Create a new Python file (File > New File > Save as example.py).
  7. Write and run a test script:
print("Hello, Python in VS Code!")

Click the "Run" button (located in the tool bar near the top right of the VSCode window)

OR

Use Cmd + Shift + B to execute the script.

You have successfully set up Python in Visual Studio Code!

Author: Georgina Woo