T-Th 9:05
or
T-Th 11:15
in Olin 155

CS 1110: Introduction to Computing Using Python

Spring 2017

Python in CS 1110

A guide by Erik Andersen, David Gries, Lillian Lee, Steve Marschner, Charlie Van Loan, & Walker White with contributions from Molly Feldman

Python comes in several shapes and sizes. To make sure that everything works properly, we require that every single person in the course use the same version of Python. You are free to either work in the ACCEL labs or to use your laptop; but whatever the case, your version of Python must be the same as what we are using in the labs. Hence, even if you already have Python installed on your computer, we ask that you install a new version (see instructions below) so you can be consistent with everyone else.

As you will see, these instructions are a bit long. Installing Python is often much more complicated than simply using it. As many people in this class have not programmed before, we have tried to make installation as simple as possible via step-by-step, "do this, do that" instructions. This is not what the rest of the course is like. You are not expected to understand what many of these steps are doing. Furthermore, these instructions are lengthy mainly because we are trying to support as many operating systems as possible. In practice, you should be able to finish the installation in 15-20 minutes.

If you have problems, and if you have a laptop, the best thing to do is to bring it in to someone to look at. Any of the course staff or consultants can help you with this. If you cannot bring in your computer, we have provided you with some instructions below. If you are having difficulty with these instructions, please email TA Molly Feldman <mqf3@cornell.edu>.


Table of Contents


Installing Python

While installing the base Python package is usually straight-forward, getting add-ons for Python can be a bit tricky. For that reason, we have tried to simplify this process into as few steps as possible. First you need to install Python. We have decided to standardize on the Anaconda version of Python. This is a free version of Python that is quickly becoming standard on this campus. You may find yourself using Python in departments outside of computer science, and they almost all use Anaconda.

Important Note About Past Semesters

In previous semesters, we used ActiveState Python instead. That version of Python conflicts with Anaconda. If you have installed this version of Python for whatever reason, you must uninstall it before following these instructions. On Windows, this can be a bit tricky as there are some hidden files. Please see a consultant if you need help with this.


Installing on Windows

The version of Python that we are using for this class is only compatible with Windows 7, 8 or 10. We do not support Vista or XP. We strongly prefer that you use Windows 10, and recommend that you upgrade now if you have not done so already. If your machine cannot support one of these versions of Windows, then you will need to work in the ACCEL lab.

For this class, we need to use Python version 2.7. If you have the 3.3 version of Anaconda already installed, this may conflict with the installation process below. In that case you will either need to remove the old version of Anaconda, or set up a special environment for this course.

 

Install Anaconda for Python2.7

Windows 32-bit
Anaconda 2.7
Windows 64-bit
Anaconda 2.7

Use one of the two links above to install the correct version for your operating system. If you are unsure, download the 32-bit version. The 32-bit version is guaranteed to work on all systems.

The file that you download is an installer app. Simply double click on it and follow directions. At one point in the installer, it will ask you whether you want to install for yourself or for all users. Select the option "All Users (requires admin privileges)", as shown below.

windows-anaconda-install

On the next page it will ask you what directory you want to install in. By default, it will install in C:\Anaconda2. Leave this alone and click Next.

windows-anaconda-directory

Finally, you will see a page with check boxes talking about your Path. Leave these check-boxes alone and complete the installation.

windows-anaconda-path

Now move on to testing your Python install!


Installing on Macintosh

The version of Python that we are using for this class is only compatible with Mavericks (10.9) or higher. If you have an older version of OS X, we recommend that you upgrade to El Capitan (10.11) or Sierra (10.12) immediately. Otherwise, you will have to work in the ACCEL lab for the semester.

For this class, we need to use Python version 2.7. If you have the 3.3 version of Anaconda already installed, this may conflict with the installation process below. In that case you will either need to remove the old version of Anaconda, or set up a special environment for this course.

 

Install Anaconda for Python2.7

Mac OS X 64-bit
Anaconda 2.7

Use the link above to install. The file that you download is an installer app. Double click on it (in Chrome you may have to click "Keep" to accept this as a 3rd party download) and follow directions.

When you get to the "Installation Type" tab, you will see the following screen:

Click on "Change Install Location" and then select the hard drive below the house (i.e. "Install on a specific disk...") as shown below:

On the next page make sure to select your main hard drive, if you have more than one (your main hard drive is usually called "Macintosh HD"). Then select "Choose Folder" to choose where to install Anaconda. You should put it in your Applications folder (very important).

Once this is done, you can then press "Continue" and proceed with the rest of the installer. It may take a couple of minutes for the full download to complete. Once it is complete, move on to testing your Python install!


Installing on Linux

Linux installation is possible, but it is not as straight-forward as the two main OS options. In particular, to install on Linux, you have to be comfortable with command shell and be ready to install files with a package installer. If this sounds daunting to you, you might want to rethink about whether you want to use Linux just yet.

For this class, we need to use Python version 2.7. If you have the 3.3 version of Anaconda already installed, this may conflict with the installation process below. In that case you will either need to remove the old version of Anaconda, or set up a special environment for this course.

In the past, we have had install parties for Linux users. We have worked to make the instructions more self-sufficient this year. However, if there is still demand for a Linux install party, post your request on Piazza.

 

Install Anaconda for Python2.7

Linux 32-bit
Anaconda 2.7
Linux 64-bit
Anaconda 2.7

Use one of the two links above to install the correct version for your operating system. If you are unsure, download the 32-bit version. The 32-bit version is guaranteed to work on all systems.

This is not graphical installer. To install it, you must navigate to the folder with the downloaded file and run it with bash. For example, if you downloaded the 64-bit version, you would type

   bash Anaconda2-4.1.1-Linux-x86_64.sh

You must use the "bash" command even if you are not using the bash shell.


2. Testing Your Basic Anaconda Install

Now that you have installed Anaconda, it is a good idea to test the installation out, using the command shell for your OS. The command shell is a text-based version of the Windows Explorer or Finder; you can use it to move and rename files and folders. It is also how we will run Python in this class.

Using the command shell requires a bit of practice, so we have created a separate page of instructions for this. But for right now, all you need to learn from that page is how to start up the command shell for your OS.

Test 2(a): can your system find any sort of Python?

Open a command shell window. Then, type

   python

(and hit return). This should put you in the "Python Interactive Shell"; you can tell this succeeded because a Python "banner" message will be printed out.

If instead you get some sort of error message suggesting that python could not be found, first reboot and try Test 2(a) again.

If you still get this kind of error message after rebooting, record the following information in order to report your problem.

  • The precise wording of the error messages you got. Copy-and-paste is best.
  • Mac and Linux users: what is the exact output when you type exactly the following at the prompt?
       echo $PATH
  • Windows users: what is the "path" environment variable set to? Here's a page that explains how to find out on Windows 7 and 8; Windows 10 should be similar.

Test 2(b): does the "banner" mention "Anaconda" and a version number of the form 2.7.x?

The red highlight below shows what we're looking for.

If this test fails, your system is running the wrong python for this class.

First, try rebooting, and run Test 2(a) and Test 2(b) again.

If you still aren't getting Anaconda, record the following information in order to report your problem:

  • The precise wording of the "banner" that you see. Copy-and-paste is best.
  • Windows users: what is the "path" environment variable set to? Here's a page that explains how to find out on Windows 7 and 8; Windows 10 should be similar.
     
  • Mac and Linux users: what is the exact output when you type exactly the following at the prompt?
       echo $PATH
     
    If the output is something where the words "/usr/bin" (which is the directory where Mac's default python is) occurs before /Applications/anaconda/bin (which is where Anaconda is), then we need to explicitly tell your system to look for Python where Anaconda was installed. Please contact a consultant for help.

Test 2(c): can you interact with the Python Interactive Shell without it immediately crashing?

The > > > symbols are the prompt. To get the shell to do something, just type a Python command. For example, type

    >>> 1+1

and hit Return (do not type the > > >; it is already there).

If anything other than the appearance of the numeral "2" happens, record the precise output, even if it's a very long error message (copy-and-paste is best) to report the problem to us.

Otherwise, you have a working installation of Anaconda.

To exit the Python Interactive Shell, type quit() or exit()and hit Return. You can also exit by typing Control-D (that is, hold down the control key and then hit the D key).



Installing Komodo Edit

All Platforms
Komodo Edit

The last program to install is Komodo Edit. Unlike Python, you will not use this program right away; we will not start to use it until the second week of class.

Technically, you can write Python modules in any text editor (e.g. a Word processor that only produces text and does not have fonts or fancy formatting). NotePad and WordPad are text editors in Windows, while TextEdit is provided by OS X. The reason we use Komodo Edit is that it is the same across all platforms. That allows you to collaborate with partners who might be working on other operating systems. Some people prefer Sublime Text, but that program is not free.

To install Komodo Edit, click the button above to take you to ActiveState's website. You will see a grey "Download Komodo Edit 10.1.4" button. Click on that button. Do not click on the red "Try Now" button; that brings you to a different product.

You may be taken to a page asking you to evangelize. By making you use this software, we are already evangelizing, so just click "Just let me download your software" to start the download. You will be asked for an e-mail address but you do not have to give it.

The file that you download will either be a MSI installer for Windows or a DMG for Macintosh. Double click on it and follow directions.


Configuring Preferences

One of the most controversial aspects of Python is that it treats spaces and tabs very differently. If you accidentally put a tab in your program, it will cause your program will crash. And you will have a hard time finding it because both tabs and spaces look exactly the same.

Most of the time, this is not a problem. Komodo does not actually put tabs in programs. Every time you hit the Tab key, it will automatically covert it into 4 spaces. However, if you have a partner using another program (like Sublime Text), they might put a tab in the file.

To make sure that you never get any stray tabs, you need to change your preferences to help you distinguish between the two. Open Komodo Edit and then select the Preferences menu option (under Edit on Windows in the Menu in the top right corner; under Komodo on Macintosh). Choose the Editor category and check the box Show whitespace characters, as shown below.

This will allow you to see both tabs and spaces, and to tell the difference between both. Spaces will look like light dots which are centered vertically on each line. Tabs will look like black arrows. These are illustrated in the examples below.

 
Python with Tabs (Bad)   Spaces Only (Good)

4. Opening and Saving Files Using Komodo Edit

We recommend that you interact with Python modules during the semester through Komodo Edit. Although the Mac and Windows versions are basically the same, we separate the instructions below by OS for maximum clarity.

On a Mac

If you do not have a file already open in Komodo Edit, the easiest way to open one is clicking "Open File" from the start page.

For Lab 02 in particular, you then want to navigate to the "lab02" folder on your Desktop and select greetings.py as below:

Once you have successfully opened the file it should like this:

If you have a file already open in Komodo Edit (or just want another method!), you can open another file either by selecting it from the Menu under "File-Open" or using the keyboard shortcut "⌘O" (Apple Command + O):

This should bring you to the same correct page as above.

What about saving files after you've made changes? If you made a change (for instance, adding your name and NetID) you will see that the filename now has an asterisk (i.e. the * symbol) following it, as show below:

To save, you can either press the save symbol or press "⌘S" (Apple Command + S):

If the save was successful, the asterisk will have been removed and the filename will appear as normal:

On Windows

If you do not have a file already open in Komodo Edit, the easiest way to open one is clicking "Open File" from the start page.

For Lab 02 in particular, you then want to navigate to the "lab02" folder on your Desktop and select greetings.py as below:

Once you have successfully opened the file it should like this:

If you have a file already open in Komodo Edit (or just want another method!), you can open another file either by selecting it from the Menu under "Open-File" or using the keyboard shortcut "Ctrl + O":

This should bring you to the same correct page as above.

What about saving files after you've made changes? If you made a change (for instance, adding your name and NetID) you will see that the filename now has an asterisk (i.e. the * symbol) following it, as show below:

To save, you can either press the save symbol or press "Ctrl + S":

If the save was successful, the asterisk will have been removed and the filename will appear as normal:


Course Material Authors: E. Andersen, D. Gries, L. Lee, S. Marschner, C. Van Loan, & W. White