CS 1: Winter 2016

CS 1 Mac Installation

This page shows you how to install the CS 1 software on your Mac. You will install a bunch of software. We have automated part, but not all, of the process.

You need to be running Mac OS 10.8 or later. If you are running Mac OS 10.7 or earlier, you need to upgrade.

If you encounter any trouble installing the software, make sure to come to the "Install-Fest," 7:00 pm to 10:00 pm on Thursday, January 7 in LSC 200.


Check to see whether you have Xcode installed on your Mac. In the Finder, click on the Go menu and then on Applications. Alnternatively, in the Finder, type Command-Shift-A. A window labeled Applications will open. Determine whether the application named Xcode is present. If it is, then skip to Download the installation script.

If you don't have Xcode in your Applications folder, you need to download and install Xcode. You'll need an Apple account so that you can get Xcode (for free) from the App Store. To get Xcode, click here, and then click on View in the Mac App Store. If you have to choose an application, choose App Store. Follow the instructions to download and install Xcode.

Download the installation script

Download the file install.sh. Put it onto your Desktop.

Open the Terminal utility

Find the Terminal program in the Utililies folder and launch it by double-clicking.

You will see a command-line prompt. Type the following:

cd ~/Desktop
bash install.sh

Follow the prompts. You will be asked to enter the password for your account on your Mac.

If you are running OS 10.11, you might get an error when you download and run install.sh (which the line bash install.sh does). The error might even occur later in this process. If you are so unfortunate as to have this happen, we have an alternate way that takes a little longer. First, download install-full.sh and put it onto your Desktop. Then, in the Terminal program, type

cd ~/Desktop
bash install-full.sh

If you continue to have problems, please contact someone from the course staff.

Install PyCharm

PyCharm is the name of the software program you will use to type in your Python programs and run them. Download it by clicking here, then clicking on Download Community:

You'll see a window that asks you to give your email address. You don't need to fill that out. If the website tells you that you must, you may click on the direct link:

The file that is downloaded is pycharm-community-5.0.3-jdk-bundled.dmg. If it doesn't open automatically, double-click on it to open it. It might be in your Downloads folder. You should see this window:

Do just what it tells you: drag the icon on the left into the folder on the right. You may close the window and eject the disk icon for PyCharm CE. The disk icon looks something like this:

The PyCharm application icon, which you should not drag to the Trash, is the one with the P and C intertwined.

Because you'll be running PyCharm often, you will probably want to add it to the dock. Open your Applications folder from the Finder. One way is to choose it from the Go menu. Alternatively, you can type ⌘A when in the Finder. You might also have it in your Favorites in a Finder window. With the Applications folder open, find the PyCharm CE icon (CE stands for Community Edition), and drag it to where you want it in the dock.

Run PyCharm, either by clicking on the icon in the dock, or by double-clicking on the icon in the Applications window. (Now, aren't you wishing you'd put it in the dock?) If you're asked whether you want to open it, click Open.

If your Mac does not have Java installed (unlikely, but possible), then you'll see a window reading To open "PyCharm" you need to install the legacy Java SE 6 runtime. If you get this message, click More Info..., which will take you to the Apple site. Download and install Java, following the prompts. If you don't see that message (and you probably won't), then you didn't need to read this paragraph.

After PyCharm opens, you might see this window:

If you do, just click OK. Then, you'll see this window:

Click Create New Project. Now you'll see something like this:

Replace untitled by the name of your project; I used cs1proj:

You need to replace whatever you see next to Interpreter by /usr/local/bin/python. To do so, click on the dots to the right of the dropdown next to Interpreter:

Then choose Add Local. You'll see a window like this:

Change the path to /usr/local/bin/python:

Click OK. You should see a window like this:

If you're running OS 10.11 (El Capitan), the Python version next to Interpreter will be 2.7.11. For OS 10.10 and earlier, you'll see 2.7.9, as above.

Click on Create. Now you'll see something like this:

You will probably also see a window like this:

Feel free to uncheck Show Tips on Startup and then Close.

Download the file pyversion.py. If you just click on this link, you'll see the code for the file in your browser window. To download it, either control-click or right-click the link and then choose Save Link As .... For convenience, move this file from your Downloads folder to your Desktop.

You're going to put this file into the project you made in PyCharm (cs1proj in my case). With the option key pressed, drag the pyversion.py icon from the Desktop to where it says cs1proj (or whatever project name you chose) in the Project tab of your PyCharm window. You should see this window:

Of course, some other path will appear instead of /Users/thc/Courses/CS 1/16W/public_html/mac_installation/pyversion.py. Click OK.

The reason that you need to hold the option key down when dragging is that if you don't, then you're moving the file, and not copying it, into the project. That means the PyCharm project will be the only place where you have the file. If you screw it up, you've screwed up your only copy. So get into the habit of holding the option key down while dragging files into PyCharm. If you don't, then the window you see will say Move file instead of Copy file.

Single-click on pyversion.py in the Project tab. Then, from the Run menu, choose Run ..., and then pyversion. (Ignore the number that appears next to it.) If all went well, a Python Console window should appear at the bottom of your window, with something like this in it:

/usr/local/bin/python /Users/thc/PycharmProjects/cs1proj/pyversion.py
2.7.9 (default, Dec 19 2014, 06:11:28) 
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)]

Process finished with exit code 0

Again, your username will replace thc, if you're running OS 10.11 you'll see 2.7.11 and other gobbledygook, and if you used a different project name from cs1proj it will appear.

Another way to run the program is to right-click on pyversion.py in the Project tab and, from the popup menu that appears, choose Run 'pyversion'.

At this point, you have a working version of PyCharm that will enable you to run Python programs. But you cannot yet run programs with graphics, so we'll set that up next.

Install the graphics software

The course staff has written a collection of Python functions that will let you easily draw graphics with your Python programs. Download cs1lib.py. You will be accessing this file a lot, so I suggest putting it in an easily accessed place, such as your Desktop. Copy (drag while holding down the option key) cs1lib.py onto cs1proj in the Project tab of PyCharm:

Next, download eyes.py. Copy eyes.py from wherever you downloaded it to onto cs1proj in the Project tab of PyCharm:

Single-click on eyes.py. Then, from the Run menu, select Run ... and then eyes. (Or right-click on eyes.py and select Run 'eyes' from the popup menu.) You should get a window like this one:

If you see this window, you have a working PyCharm IDE! Yay!

A note: You might also see some red text in the Console tab, with some indecipherable but ominous message looking something like this

Python[11261:1044673] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead. 

You'll see this message whenever you use the CS 1 graphics package. Foreboding though it appears to be, it is harmless. Don't worry about it.

Close the window containing the graphical output from the eyes.py program.

Make the right Python interpreter the default interpreter

When you create a new project in PyCharm, you get a choice of Python interpreters, and the default is not necessarily the one that you have just set up (/usr/local/bin/python). You can make it so that /usr/local/bin/python is the only interpreter that PyCharm considers when setting up a new project.

From the File menu, choose Default Settings .... On the left side of the window, choose Default Project. You should see something like this:

Click on Project Interpreter. Then click on the dots on the right:

Then click on More .... You should see a window something like this:

For each choice other than the one that contains /usr/local/bin/python, click on it and then click on the minus sign at the bottom of the window, so that you remove that choice:

When you've removed all but /usr/local/bin/python, the window should look like this:

If you're running OS 10.11, you'll see 2.7.11.

Click OK, and click OK again. Now when you create a new project, the only interpreter choice will be the one you want.