A band with three musicians

William J. Turkel and Adam Crymble

This lesson will help you set up an integrated development environment for Python on a computer running a Mac operating system.

Peer-reviewed

edited by

  • Miriam Posner

reviewed by

  • Jim Clifford
  • Amanda Morton

published

| 2012-07-17

modified

| 2012-07-17

tested

| 2023-11-16

difficulty

| Low

DOI id icon https://doi.org/10.46430/phen0012

Great Open Access tutorials cost money to produce. Join the growing number of people supporting Programming Historian so we can continue to share knowledge free of charge.

Available in: EN (original) | PT | ES

Contents

Back up your computer

Mac users can take advantage of the Time Machine for this.

Install Python v.3

You may already have Python 2 installed on your machine. This version of Python will be deprecated at the end of 2019, so you will have to install Python 3. Download the latest stable release of the Python programming language (Version 3.8 as of November 2019) and install it by following the instructions on the Python website.

Create a Directory

To stay organized, it’s best to have a dedicated directory (folder) on your computer where you will keep your Python programs (e.g., programming-historian). Save it anywhere you like on your hard drive.

Install a text editor

There are many text editors that you can use to write, store, and run Python commands. Sublime Text is the one used in this lesson. If you prefer to use another editor, there are many other text editing options. Some of our testers prefer a program called BBEdit. Which you use is up to you. You can download a copy of Sublime Text from the Sublime Text website.

Set up in Sublime Text

Now you need to set up the editor so that you can run Python programs.

From the menu, choose Tools -> Build System -> Python.

Step 2 – “Hello World” in Python

It is traditional to begin programming in a new language by trying to create a program that says ‘hello world’ and terminates. We will show you how to do this in Python and HTML.

Python is a good programming language for beginners because it is very high-level. It is possible, in other words, to write short programs that accomplish a lot. The shorter the program, the more likely it is for the whole thing to fit on one screen, and the easier it is to keep track of all of it in your mind.

Python is an ‘interpreted’ programming language. This means that there is a special computer program (known as an interpreter) that knows how to follow instructions written in that language. One way to use the interpreter is to store all of your instructions in a file, and then run the interpreter on the file. A file that contains programming language instructions is known as a program. The interpreter will execute each of the instructions that you gave it in your program and then stop. Let’s try this.

In your text editor, create a new file, enter the following two-line program and save it to your programming-historian directory as hello-world.py

# hello-world.py
print('hello world')

Your chosen text editor should have a “Run” or “Build” button that will allow you to execute your program. If you are using Sublime Text, click Tools -> Build (or type ⌘B). If you are using BBEdit, click on the “#!” button and Run. If all went well, it should look something like this:

'Hello World' in Python on a Mac with BBEdit

‘Hello World’ in Python on a Mac with BBEdit

Or, with Sublime Text:

'Hello World' in Python on a Mac with Sublime Text

‘Hello World’ in Python on a Mac with Sublime Text

Interacting with a Python shell

Another way to interact with an interpreter is to use what is known as a shell. You can type in a statement and press the Enter key, and the shell will respond to your command. Using a shell is a great way to test statements to make sure that they do what you think they should. This is done slightly differently on Mac, Linux and Windows.

You can run a Python shell by launching the ‘terminal’. On the Mac, open the Finder and double-click on Applications -> Utilities -> Terminal then typing “python3” into the window that opens on your screen. At the Python shell prompt, type

print('hello world')

and press Enter. The computer will respond with

hello world

When we want to represent an interaction with the shell, we will use -> to indicate the shell’s response to your command, as shown below:

print('hello world')
-> hello world

On your screen, it will look more like this:

Python Shell in Mac Terminal

Python Shell in Mac Terminal

Now that you and your computer are up and running, we can move onto some more interesting tasks. If you are working through the Python lessons in order, we suggest you next try ‘Understanding Web Pages and HTML.’

About the authors

William J. Turkel is Professor of History at the University of Western Ontario.

Adam Crymble, University College London.

Suggested Citation

William J. Turkel and Adam Crymble, "Setting Up an Integrated Development Environment for Python (Mac)," Programming Historian 1 (2012), https://doi.org/10.46430/phen0012.

Great Open Access tutorials cost money to produce. Join the growing number of people supporting Programming Historian so we can continue to share knowledge free of charge.