# 5.3. Some Special Mac Instructions¶

While the Python language changes slowly, operating systems and setup methods change more rapidly with succeeding versions. The attempt here is to keep all such information in one place for the Mac OS-X operating system. It may become out of date at any time.

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

## 5.3.1. Versions¶

I will use Python 3.8+ to mean the current version of Python, with version number at least 3.8.1. Make sure you have the latest recommended version installed from https://www.python.org/downloads/. Download the pkg file and double click to execute.

## 5.3.2. Editing by Default in Idle¶

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.8+. If you can double click on a .py file in my examples, and Idle opens as soon as you have installed Python 3.8+, 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 IDLE.app 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 IDLE.app there.
3. You may see IDLE.app lower down in the list of options. Then select it there.
4. If you did not see IDLE.app 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.8 folder. Open it and select Idle.app.
5. The Info window should become active again. Be sure that now under Open with: you see IDLE.app.
6. Under the IDLE.app 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!
8. Then if you should happen to want to directly run a Python file from the Finder window, you will need to select the file with control-click or right-click and select the latest Python Launcher for Python 3.

## 5.3.3. 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.

## 5.3.4. Chapter 4 CGI Instructions¶

### 5.3.4.1. 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.

### 5.3.4.2. Setup: Making CGI Scripts Executable¶

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/CGIfix.py is used to give direct Unix/Mac/Linux executability to CGI files for Chapter 4.

In the finder open your www directory. You can open CGIfix.py in Idle and run it. Note the comment that the file cgiServerScript was created. This is used to lauch the local server.

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 CGIfix.py 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 CGIfix.py)! Running it extra times does not hurt.

## 5.3.5. 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.