M, F 2:30-3:20
in Olin 165

CS 1133: Short Course in Python

Fall 2017

Python in CS 1133

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 instructor Walker White <wmwhite@cs.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.

Once you have the base Python install, you need to install the "Cornell Extensions". These are 3rd party extensions packaged by us (but not made by us) to fit into Python. These extra packages include things like graphics capabilities to make games and flashy applications.

Before you install these, be sure to completely read the instructions for your operating system. While you are unlikely to make any mistakes, it is best for you to do things in exactly the order we tell you to. As we said, you do not need to understand what is going on here.

Important Note About Past Semesters

The installation this semester is brand new, because this is our first year using Python 3. In previous years, we used Python 2, which is completely incompatible with the more recent version of Python. If you have installed an older version of Python for whatever reason, we suggest that you 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 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 3.6. This is the most recent version of Python for Anaconda. If you have the 2.7 version of Anaconda already installed, this may conflict with the installation process below. Inthat case you will either need to remove the old version of Anaconda, or set up a special environment for this course. If you do the latter, you will need to install CornellExtensions manually. Ask one of the course staff to help you if you need to do this.

 

Install Anaconda for Python3.6

Windows 32-bit
Anaconda 3.6
Windows 64-bit
Anaconda 3.6

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:\ProgramData\Anaconda3. We need this folder for Cornell Extensions, so leave this alone and click Next.

windows-anaconda-directory

Finally, you will see a page with check boxes talking about your Path. You must select the top box, even though it warns you not to. If you do not check this box, you will not be able to use Python from the Command Prompt.

windows-anaconda-path

 

Install the Cornell Extensions

Windows (All)
Extensions

Download the file from the link above. After downloading, you will see that this is a folder with a zipper on it. Double click on the folder. This will open an Explorer Window with another folder inside of it called CornellExtensionsInstall. Drag the CornellExtensionsInstall folder on to your Desktop. This is important, as the installation will not work if you click on the installer while it is still inside the folder with the zipper.

Now that you have a copy of CornellExtensionsInstall on your Desktop, open this folder (again, not the one in the zipped folder!). Inside, you should see the following two items:

Double-click on the file that is named install. This will pop up a window with a lot of scrolling text in it. Do not close the Window until you see the line that says "Installation Complete", and asking you to hit a key. If you close the Window too early, you will have to install a second time.

On some Windows systems, the security settings may prevent you from installing Cornell Extensions. On those systems, you will see a security message like the one below.

If this happens to you, click on the "More info" link. When you do that, the information message should now look like this:

Click the "Run anyway" button to complete the installation.

Once you have finished with the Cornell Extensions, you should test your installation.


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) immediately. Otherwise, you will have to work in the ACCEL lab for the semester.

For this class, we need to use Python version 3.6. This is the most recent version of Python for Anaconda. If you have the 2.7 version of Anaconda already installed, this may conflict with the installation process below. Inthat case you will either need to remove the old version of Anaconda, or set up a special environment for this course. If you do the latter, you will need to install CornellExtensions manually. Ask one of the course staff to help you if you need to do this.

 

Install Anaconda for Python3.6

Mac OS X 64-bit
Anaconda 3.6

Use the above to install the correct version for your operating system. The file that you download is an installer app. Simply double click on it and follow directions. You may wish to change the install location on this page:

However, there is something weird with the OS X installer when you do this. In particular, you may see the following error:

This problem is easy to solve. If you just click on the house, it will now look like this.

It is okay for you to install Anaconda this way. However, we would prefer that you install it for all users instead. Do that, select the hard drive icon below the house. When you are done, it should look like this.

Select the button Choose Folder to the right. This will tell it where to put Anaconda. We recommend that you put it in the Applications folder.

When you download this file, you will get a web page asking you to fill in some information. Ignore this web page. You do not need to fill in the information; your download has started already.

 

Install the Cornell Extensions

Mac OS X 64-bit
Extensions

The last step is to install the Cornell Extensions for CS 1133. Download this file from the link above. This is a reasonable large file. If you find the download time too slow, you can come to consulting hours to get a copy, or use a USB drive to get a copy from someone who already has it.

After downloading the file, double click on it to unzip the contents into a folder somewhere on your computer. Once again, you see will a package installer. Double click on the package installer. You may see a warning telling you that this is not an official installer (because we made it). If that happens, you will need to control-click the installer and select Open from the drop-down menu.

If the installer launches properly, you will see the following window.

Follow the directions for the installer. Your installation is now complete. Once this is done, you are now are ready to test your installation.


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 3.6. This is the most recent version of Python for Anaconda. If you have the 2.7 version of Anaconda already installed, this may conflict with the installation process below. Inthat case you will either need to remove the old version of Anaconda, or set up a special environment for this course. If you do the latter, you will need to install CornellExtensions manually. Ask one of the course staff to help you if you need to do this.

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 Python3.6

Linux 32-bit
Anaconda 3.6
Linux 64-bit
Anaconda 3.6

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 Anaconda3-4.4.0-Linux-x86_64.sh

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

You may install Anaconda where ever you wish. By default, it installs in your home directory. However, we prefer to install it in /usr/local. The choice is up to you.

 

Install the Cornell Extensions

Linux (All)
Extensions

You will need to install a few extra modules that are unique to Cornell. Download the file from the link above and unzip it. Inside this folder you will see a file called setup.py. Use this file to install the extensions with the following command:

   python setup.py install

This will install the pacakges into your Python installation. Note that if you installed Python outside of your home directory (e.g. in /usr/local), you will need to use sudo with this command to give it access priviledges. If you are unsure of how to do this, you should rethink about about whether or not you want to use Linux.

Install Kivy

The last step is potentially the trickiest. Kivy is the graphics library that we will be using for several of the assignments in this class. In the past, students have had to compile this library from source code. However, Kivy now has installers for several flavors on Linux. Look at the downloads page for more information

Once Kivy is installed, you are are ready to test your installation.


Getting Started with Python

Now that you have installed Python, it is a good idea to test it out. While you do not need to know anything about Python yet, you do need to learn how to run Python programs that are already made for you.


The Command Shell

The first thing that you need to do is to familiarize yourself with 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. Right now, all you need to know is how to start up the command shell; you do not need to know any special commands. Start the command shell for your OS and type

 python

This will put you in the "Python Interactive Shell".

The Python Interactive Shell looks exactly like the command shell except that it takes Python commands (and does not respond to operating system commands to list files or change the working directory). While the command shells are different for all operating systems, the Python Interactive Shell should look and behave exactly the same way for everyone. On Windows, it will look something like this.

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). See what happens?

To exit the Python Interactive Shell, type quit() and hit Return. You can also exit by typing Control-D.


Testing a Module

It is possible to run Python modules from the command shell as well. A module is a file (ending in suffix .py) containing Python code. We will use them throughout the course. To run a module, you type

 python <filename>

from the command shell. Do not try to type this in the Python Interactive Shell. This can be a bit confusing at first; it is important to keep the following straight:

  • The command shell is a program for accessing files via text based commands. You start Python in this program, but it is not Python.
  • The Python Interactive Shell is a program that runs inside the command shell. It looks a bit like the command shell, but you can tell the difference by the presence of the > > > prompt.

Running a module does not start the Python Interactive Shell. It runs all of the commands in the file, and then quits immediately when done with the file.

To test that your installation is working properly, we have a cute Python module that displays a GUI with the phrase "Hello World!" inside it, as shown below.

To try out this module, download the file the file helloApp.py and put it in some easy to find folder. Open up a command shell and navigate to this folder using the drag-and-drop trick for changing directories. Then type the command

 python helloApp.py

If you get the window shown above, congratulations! You have successfully installed all the Python libraries needed for this class.

If the Window does not show, look very carefully at the error messages. If it says it cannot find the file helloApp.py, then you did not use the drag-and-drop trick correctly; we recommend that you practice with the command shell tutorial some more. Otherwise, there is a problem with your installation of Piazza. Post your error message to Piazza and we will try to help you out.


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. The purpose of Komodo Edit is to make these mysterious modules that you tested in the previous step.

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 Active State's website. You will see a red "Download Komodo Edit" button. Click on that button. You will be taken to a page asking you to evangelize. By making you use this software, I am 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; 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)