Some Special Mac Instructions

I will assume a version of Max OSX of at least High Sierra (10.13 or later). Upgrades are free.

This document supersedes any conflicting instructions in the tutorial itself. As versions of Python and operating systems have changed, some old usage instructions get out date. I am keeping all the latest system information in this document.


I will use Python 3.7+ to mean the current version of Python, with version number at least 3.7.3. Make sure you have the latest recommended version installed from Download the pkg file and double click to execute.

Your Login ID

The normal place for you to have my examples folder is under your home folder, which has the same name as your Login ID. If you are just creating a login ID, it will save some hassle in Chapter 4, if your login ID does not have a space in it. "Andy" or "AndyHarrington" would be fine for me, but

"Andy Harrington"

would bomb the server in Chapter 4.

If You Have a Blank in your Login ID

The local server program central to chapter 4 bombs with folder paths with a blank in the name.

If you have a blank in your Login ID, it is not so easy to change. Instead make a folder outside of your home folder:

  1. Go to the Macintosh HD folder and create a folder (like "comp150") with no blank in it! You will need administrative privileges, and will be prompted to enter your password.
  2. I suggest that you move my examples folder, or just the sub-folder www so it is under your new folder. For Chapter 4 test my examples and add your work there.

Folder For My Examples

Wherever you plan to unzip my Python examples folder from you need to make sure that my www folder, and any other folder where you put later .cgi files does not have a blank in its name, or any folder in which it is a sub-folder. If you have a "comp 150" parent folder, you might rename it "comp150".

Running VS. Editing

Editing by Default

You will be working mostly with files ending in .py -- Python source files. Most of the time you will be editing them and running them in IDLE, so the best default behavior when opening a file with extension .py is to have it open in Idle 3.7+. If you can double click on a .py file in my examples, and Idle opens as soon as you have installed Python 3.7+, great - you should skip the rest of this section.

If Idle did not open, here is how to change the default behavior:

  1. In the Finder go to a file in my examples folder with the .py extension. and right click or control click on it. Select Get Info.
  2. In the Info window that pops up, In the drop-down menu for Open with:, you want to see on the top line (meaning it is already the default). You may possibly also see the version listed if you have several. Presumably you are going through this because you do not see there.
  3. You may see lower down in the list of options. Then select it there.
  4. If you did not see in the drop-down list at all:
    • Select Other....
    • A window of apps pops up. Toward the bottom is a check box for "Always Open With". Check it.
    • If you do not see a Python folder in the list, just below the bottom of the page change Recommended Applications to All Applications
    • Now you should see a Python 3.6 folder. Open it and select
  5. The Info window should become active again. Be sure that now under Open with: you see
  6. Under the you should see a button, Change All.... So that you never have to go through all these steps again, be sure to click that button. A confirmation window will pop up. Select Continue.
  7. Now you can close the Info window, and you should be able to open all .py files directly in Idle for editing by double clicking in the Finder!


Starting The Idle Shell


  • Use Spotlight with If there is more than one version of, make sure you choose one for Python 3.7+. This is a good approach the first time to check that Idle is properly installed. The disadvantage of this approach is that Idle starts in your Documents folder (more below).
  • You may open a Python file ending in .py into an Idle Edit window by selecting it directly in a Finder window if the defaults are set as discussed above. Instead you can Ctrl-click on the file, select Open With, and then choose Idle for Python 3.7+.

Opening Files from Inside Idle

You may select Open in the File menu inside Idle.

Caution: the behavior depends on what window is active at the moment - a file editing window or the Shell window:

  • If the active window is some file editing window when you use the Idle File menu to open a file, your search will start in the same folder as the file you are editing (generally the desired behavior).
  • If you select File Open from the Shell window, the starting folder depends on how you started Idle:
    • If you started Idle from Spotlight or opened a file in the Finder, then your search will start in your Documents folder, probably not what you want.
    • If you started Idle from a terminal, you open to the directory where you gave the command to start Idle.

Saving Files

If you have modified a file and want to save it under a new name, make sure the file is in the active window (the shell window is not active), go to the File menu and Save. It is easiest if you save all files in the same folder: my examples folder (except in Chapter 4). The default is to save the file as a Python file, ending in ".py". If that is not what you want, note the Format field at the bottom of the Save dialog and change it to All Files.

Running Program Files

Make the Edit window for the file you want active by clicking in its window, then go to the Run menu and select Run Module. Note the F5 shortcut key.

Running Graphics (Chapter 2)

The graphics window likely comes up behind an unneeded Console Window. You can close the console window, and click on the graphics window title bar to bring it to the front. If you run the program from inside Idle,

Chapter 4 CGI Instructions

Remember this is the time when it is critical not to have .cgi files under a folder with a blank in the name. See the earlier discussion.

CGI Files on My Server Do Not Work!

The administrators of my server changed the security parameters, so now the links to run cgi scripts on my server do not work. Just use the ones the the local server on your machine, as discussed below. Do not click on Ch4 links to URL's at

Opening .cgi Files in Idle

By convention the server programs that you will be writing end in ".cgi". That is not an extension that is automatically associated with Idle for editing. You will want to change the association. Do it the same way as the instructions above for getting .py files to open in Idle by default, except choose a .cgi file in my www folder, and go through the same procedure.

Setup: Making CGI Scripts Executable

Make sure you have completed the previous section successfully before going on to this section.

A complication on a Mac, like any Unix derived system, is that programs that you run must be explicitly marked executable. (On Windows it follows from the file extension, like .exe.) The examples/www folder may not have the cgi files marked executable (nor have several other technical things right).

The example program examples/www/ is needed to give direct Unix/Mac/Linux executability to CGI files for Chapter 4.

Remember the www directory cannot have a directory name in the path down to that directory with a space in it. If you got that wrong, go back to the previous section.

In the finder open your www directory. You can open in Idle and run it. Note the comment that the file cgiServerScript was created. You need that in the next section:

Running CGI Scripts

Important! Particularly if you later copy in a CGI script from a Windows machine, or if you create any new cgi script in the www directory, make sure it becomes executable (and possibly fix some other technical things) by launching again.

If you forget this, and the file is not executable, nothing happens in the browser when you try to run it, and the error message in the server window is very unhelpful - it says "... File not found ...". Make sure you make new CGI files executable (with!

If you create and edit a cgi file inside Idle, remember you cannot run it from inside Idle. After editing, be sure to check the syntax, using alt/option-X. You should close the file in Idle before running

When you want to test a cgi script, you first need to have launched the local CGI Server, however opening and running in Idle does not work!

Instead make sure all your files needed by the cgi server (.html, .cgi, are in the same folder as the file created there by cgiServerScript. (Distinguish the separate file for Windows, startServer.cmd: Ignore that.)

In the Finder double click on cgiServerScript. This should start a window announcing the start of the CGI server. (Then you can leave it running for as long as you want to test .cgi files in the same folder.) Do not have several copies of the CGI server running at once!

At this point you can do all the web server based activities in Chapter 4, with the only extra step being the running of when you create a new CGI script in the www directory, or copy one from Windows. There are a number of steps: be sure you carefully go through the list in the tutorial. Remember, html files calling a cgi file, and cgi files used directly are only run in your web browser with a URL starting with localhost:8080/. Otherwise nothing dynamic happens.

Terminal Use (Optional)

To use the Hands-on Python Tutorial, the information above should be sufficient to get your Mac usage going. Terminals are quite useful in other contexts: There are many things that can be done from such a window that cannot be done from the Finder or with an App.

If you would like a bit more background, read on.