T-Th 9:05 |
CS 1110: Introduction to Computing Using Python Spring 2015 |
||||||
Main
About: Announcements Staff Consultants Times & Places Calendar Materials: Texts Python Command Shell Terminology VideoNote Learning: Lectures Assignments Labs Assessment: Grading Exams Resources: CMS Piazza AEWs FAQ Python API Python Tutor Style Guide Academic Integrity |
Python in CS 1110Python 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 consultants can help you with this. If you cannot bring in your computer, we have provided you with some instructions below. Table of ContentsInstalling PythonWhile 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 ActiveState Community Edition of Python. This is a free version of Python that is fairly complete and has a lot of nice features. You will notice that their webpage is trying to upsell you to a paid version of Python. Ignore that. The only case in which you will not use ActiveState Python is if you are running Mac OS X 10.9 or greater. In that case, you will use the Python that comes packaged with your operating system. There are known issues with ActiveState on the more recent versions of OS X, so it is important that you do not use it in this case. 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 either the ActiveState or Mac OS X 10.9 version of 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. Installing on WindowsThe version of Python that we are using for this class is only compatible with Vista, Windows 7, and Windows 8. In the unlikely event that you are using Windows XP, you will not be able to use this version of Python. In that case you will either need to upgrade your OS or work in the ACCEL lab.
This installation process will put Python in the directory Install ActiveState PythonGo to the ActiveState web page and download the free 32 bit Community Edition of Python 2.7.8. This should be the first big blue button on the right. We cannot say the following enough: Do not download the 64 bit version. The 32 bit version is called x86, while the 64 bit version is called x64. Even if you are using a 64 bit version of Windows, you must install the 32 bit version of Python. Many of the extra features in the Cornell Extensions will not properly work with 64 bit Python. If you use 64 bit Python, you will not be able to complete some of the later assignments in this class. In addition, make sure you have Python 2.7.8 or other version starting with 2.7, and not Python 3.3.4. or any other number starting with a 3. Python 3 is "bleeding-edge" software and too new to safely use in this course (particularly because it is not backwards compatible with Python 2.7). When you download this installation file, you may get a web page asking you to fill in some information. You can ignore this web page. You do not need to fill in the information; your download has started already.
The file that you download is a MSI installer. Simply double click on it and follow
directions. At one point in the installer, it will ask you what directory you want
to install in. By default, it will install in
Install the Cornell ExtensionsDownload the file CornellExtensionsWindows.zip. This is a big 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 this zipped folder. This will open an Explorer Window
with another folder inside of it called
Now that you have a copy of
Double-click on the file that is named Once you have finished with the Cornell Extensions, you should test your installation. Updated 8/28: Because of some problems with installations, we suggest that you reboot your machine after installing Cornell Extensions. There have been a few instances where the users typed in the command python, and they received an error message that Python could not be found. This error is usually fixed by rebooting the machine. Installing on MacintoshThese instructions are a bit different depending on which version of the OS you are running. Make sure you know your version and pay attention to where the instructions are different. Snow Leopard (10.6), Lion (10.7), and Mountain Lion (10.8) will use ActiveState Python, like on Windows. However, Mavericks (10.9), Yosemite (10.1) or later will use the Python that comes with the OS. If you are unsure of your OS, chose About this Mac under the Apple Menu. Installation for OS X involves either two or three steps depending on your OS version. If you are running OS X 10.8 or earlier you will need to install ActiveState Python, XQuartz, and the Cornell Legacy Extensions. If you are running 10.9 or later, you can skip the Python installation; in that case you will only install XQuartz and the Cornell Mavericks Extensions. All of these are outlined below. The differences between OS X versions can make installing for OS X a bit tricky. Therefore, you need to be extra careful in to test your installation. If you are having trouble, we have steps to figure out what the problem is. Install ActiveState Python (OS X 10.8 and Earlier)Go to the ActiveState web page and download the free Community Edition of Python 2.7.2 (or other number starting with 2.7). This should be the big blue button on the right. Make sure you have Python 2.7.2 and not Python 3.2.2 (or any other number starting with 3). Python 3 is “bleeding-edge” software and too new to safely use in this course (particularly because it is not backwards compatible with Python 2.7). 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. The file that you download is a DMG. Double click on it and it will turn into a virtual disk drive containing a package installer (a icon that looks like a brown box). Double click on the package installer and follow the directions.
You will note that this installation requires Snow Leopard (10.6) or later (the current version of OS X is Mavericks, 10.9). The Python libraries in this class require a 64 bit OS, and cannot support older versions of OS X (such as Leopard, 10.5). If you OS version is this old, you will either need to upgrade your OS or work in the ACCEL lab. As Snow Leopard is now five years old, this is not an unreasonable request.
If you are running MacOS 10.8, it may complain that the package is from an unidentified developer. To get around this, control-click on the package and select “Open,” then click “Open” again in the resulting dialog box. Install XQuartz (All OS X Versions)All of the OS X versions need XQuartz, a library used by scientific computation programs. Download the file XQuartz-2.7.7.dmg. Double click on this file to unzip the contents into a folder somewhere on your computer. Like ActiveState Python, you will see a package installer. Double click on the package installer and follow the directions. Install the Cornell Extensions (All OS X Versions)The last step is to install the Cornell Extensions for CS 1110. The correct set of extensions depends on your operating system version:
Download the correct file for your operating system. These are both big files. 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 and follow the directions. Your installation is now complete. Once this is done, you are now are ready to test your installation. Installing on LinuxLinux 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 compile some of the software from source. If this sounds daunting to you, you might want to rethink about whether you want to use Linux just yet. 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 ActiveState PythonThe first step is to install Python. Chances are, your Linux machine already has a version of Python. However, one of the key things about this class is that we want to ensure that every Linux distribution is exactly the same. So you need to install the ActiveState version. Go to the ActiveState web page and download the free Community Edition of Python 2.7.8 (or other number starting with 2.7). This should be the big blue button on the right. Make sure you have Python 2.7.8 and not Python 3.3.4 (or any other number starting with 3). Python 3 is “bleeding-edge” software and too new to safely use in this course (particularly because it is not backwards compatible with Python 2.7). Unlike Windows, it is not necessary to download the 32 bit version. You may download the 64 bit version of Python, should you desire. However, your installation must be consistent. That means that every single package that you install must be the same version (if there is a choice). Install the Basic PackagesThe Cornell Extensions package that we provide for Windows and OS X contains a lot of extra Python packages. Instead of one double-click solution, you will need to install each one of these separately.
We find that the easiest way to install is with pip install <package-name>
To guarantee success, you generally need to run sudo pip install cython
In the few instances where Now that you know how to install a Python package, here is a list of all the basic packages that you need to install. Install the Custom Cornell ModulesThere are a few extra modules in Cornell Extensions that are unique to Cornell. These modules will be used in the early labs and assignments, so it is important to install them.
The hard part of this step is locating the /usr/local/lib/python2.7 but we are not sure (and it may not be the same for all distributions). If you do find it, post its location on Piazza so that we can share the information with others. Once you do find this directory, you need to download the following five files and put them inside it. It is a good idea to change the ownership and permissions of these files to match those of the others in this folder (if you know how to do that). Install KivyThe last step is also 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. Fortunately, the website now appears to have friendly instructions for installing on Linux. We have never tried these instructions ourselves, however, so you are on your own here. Again, if you would like an Linux install party, post your request on Piazza. Once Kivy is installed, you are are ready to test your installation. Getting Started with PythonNow 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 ShellThe 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 Testing a Module
It is possible to run Python modules from the command shell as well. A module
is a file (ending in suffix 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:
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 Troubleshooting OS X 10.8 and EarlierIf your installation is not working and you are using OS X, there is one more thing you should try before posting to Piazza. Remember that you now have two versions of Python and we need to make sure that you are running the correct one. The "application path" is how the Terminal finds the correct version of Python to use. Launch the Terminal and enter the command which python This command asks the Terminal "which version of Python are you using?" If you get the answer /usr/local/bin/python then you have the correct version of Python. In that case, your installation problem must be somewhere else. However, if you get the answer /usr/bin/python this is the Apple Python, which is a problem. If you are absolutely certain that you followed all of the steps above, download the file install.sh. Put this file on your Desktop. Open up a Terminal window, and type bash Desktop/install.sh Quit and restart the Terminal. Type which python again to check if the problem is fixed. If the problem persists, it is time to see a consultants, as this is not a problem that is easy to fix over Piazza. Installing Komodo EditThe 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 third 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. To install Komodo Edit, first download the installer from Active State's website (click on the blue "Download Komodo Edit" button after you follow that link). Do not download Komodo IDE, as that is the paid version. Again, you will be redirected to a website asking for some personal information; ignore that and wait for the download to finish. 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 PreferencesOne 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. To solve this problem, 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.
|
||||||
Course Material Authors: D. Gries, L. Lee, S. Marschner, C. Van Loan & W. White (over the years) |