Python in CS 1110
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 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 instructions. 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 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 post on Ed Discussions or send email to Joaquin Rivera.
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. In the past, we simplified this process by recommending students install the Anaconda version of Python. However, the licensing restrictions on that distribution have become incompatible with this course, and we no longer recommend it.
Unfortunately, this means that our recommended Python installation now depends upon your operating system. Find your operating system below and be sure to completely read the installation instructions. 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 Windows
Windows Store Python 3.12.10 |
This class supports either Windows 10 or 11. We do not support Windows 8 anymore, nor do we support older 32-bit versions of Windows. If you are using an older version of Windows, we recommend that you upgrade now before the semester starts. If your machine cannot support a newer version of Windows, you will need to work on the lab computers in Phillips 318.
For this class, we recommend Python version 3.12.10. This is an extremely stable version of Python and has been tested on other platforms as well. Newer versions of Python are still going through bug fixes, and so we are not ready to switch to them yet.
The above link will actually take you to the Microsoft Store. Ironically, we have found this is the best version of Python for Windows. The version from python.org does not install Python in a way that you can use from the command shell. This version is fully up-to-date and it properly installs the command line tools.
Because this is a Microsoft Store app, it is extremely easy to install. Just click the Install button and follow the instructions.
Installing on Macintosh
macOS (Universal) Python 3.12.10 |
This class supports any version of macOS starting from Big Sur (macOS 11) or higher. We do not support Catalina (macOS 10.15) or older versions of macOS. If you are running an Macintosh with an operating sytem that old (pre-2019), it is likely that your machine is too old for this course. In that case, you should talk to the course instructor about your options, which may include working with the lab computers in Phillips 318.
Macintosh computers come with Python built-in, but you should not use that version of Python. That version is locked down, and it will not allow us to add extensions. Instead, you are going to download a second copy of Python from python.org. This will not delete the built-in Python (which macOS needs), but instead will exist at the same time.
Most applications these days require that you specify whether your computer is running an Intel chip or Apple Silicon. However, the Python installer is a Universal installer, meaning it works with all Macintoshes. Download the installer and run it. Follow the instructions; you do not need to customize your installation.
Installing on Linux
Linux (Source Code) Anaconda 3.12.10 |
Linux installation is possible, but it is not as straight-forward as the two main OS options. In particular, python.org does not provide a pre-built binary for Linux. That means that Linux users must be comfortable with building a program from source code. If you are not comfortable with this, you should rethink about using Linux for this course.
Download the file above, and then navigate your Terminal
to the directory containing the file. This file is a .tgz
file, meaning it is
in a compressed format. To uncompress it, type
tar -xzf Python-3.12.10.tgz
This will create a folder named Python-3.12.10
in the same directory. Navigate
to that folder and type
./configure
make
make test
This will build and verify Python for your machine. It is possible that you may fail a few of the tests. This is okay, as not all machines support all Python features. But if you get a fatal error, you may have to reconsider your usage of Linux.
If Python is successfully built, you can install it with the command
sudo make install
This will install Python as python3
.
Setting-Up Python
The Python that you have installed on your computer is affectionately called “vanilla Python”. That is because it does not come with many of the third-party add-ons that other distributions do. However, these add-ons are what given Python a lot of its power, and we will need them for this course. So in this section, you are going to finish your Python installation by including them.
The instructions in this section are the same for all operating systems.
Running the Python Shell
Before you do anything else, you must fully test out your Python installation. You need to verifyt that works correctly before installing additional packages. This requires that you 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.
Installing the Extensions
All Platforms Python Extensions |
Once you confirm that Python is working properly, click on the button above to
download the file extensions.py
. This file is what as known as a
Python script. That is a file containing Python code. To run a script, 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. You can tell it is running by the presence of the >>> prompt.
Running a script 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.
In order to run a script, your command shell needs to be in the same directory
as the file extensions.py
. Put this in an easy-to-find folder, and navigate
to this folder using the
drag-and-drop
trick for changing
directories. When you are sure you are in the correct directory, type
python extensions.py
The program should either tell you that the packages were successfully installed or have already been installed. If this script fails, look very carefully at the error messages. If it says it cannot find the file, then you did not use the drag-and-drop trick correctly. We recommend that you practice with the command shell tutorial some more. Otherwise, this means is a problem with your installation of Python. Post your error message to Ed Discussions and we will try to help you out.
Running the Test Scripts
To test that the extensions have been installed properly, we have created two cute Python scripts that display a GUI with the phrase “Hello World!” inside it, as shown below.
To try these out on your computer, download the following files:
Once again, put these both in some easy-to-find folder and navigate the shell
to that folder. To run hello_tk.py
, type
python hello_tk.py
To run hello_kivy.py
, type
python hello_kivy.py
If you have installed everything correctly, you should see the image above each time. The reason we have two scripts is because there are actually two different ways to create GUIs in Python, and we need to make sure that both work.
Once again, if there are any problems, post your error message to Ed Discussions and we will try to help you out.
Installing Pulsar
The last program to install is Pulsar. Unlike Python, you will not use this program right away. In fact, we will not start to use it until the third week of class. The purpose of Pulsar is to make these mysterious scripts that you tested in the previous step.
Technically, you can write Python scripts 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 MacOS. The reason we use Pulsar is that it is the same across all platforms. That allows you to collaborate with partners who might be working on other operating systems. While there are some alternative editors out there to use, we have decided to standardize on Pulsar because it is immediately ready for Python with little configuration necessary.
To install Pulsar, your will need to pick the correct installer for your operating system.
Pulsar on Windows
Windows (All) Pulsar |
For the most part, the installer for Windows is straight-forward. Unfortunately, this installer has not been official verified with Microsoft (but it is okay, we promise). That means you will see the following error message.
Click on the link More Info to get a button that says Run Anyway as shown below.
You will be given a choice to install it for yourself, or for everyone. We recommend installing for everyone.
Choosing this option will prompt you to install Pulsar in the directory shown
Click Install to finish the installation.
Pulsar on macOS
macOS (Silicon) Pulsar |
macOS (Intel) Pulsar |
Pulsar does not have a universal installer for macOS, which means that you need to pick the correct version for your CPU (Intel or Apple Silicon). The last Intel Macintosh was produced in 2019, so it is highly unlikely that you have one. With that said, students do like to hold on to machines for a long time, so there is also one person.
To determine your CPU, you should select About This Mac from the Apple Menu. For example, in the picture below, the Mac is an Intel Mac running Monterey (macOS 12).
One the other hand, in this picture we have an Apple Silicon Macintosh running Ventura (macOS 13).
Click on the correct version for your Macintosh. The downloaded file should be
a .dmg
file. Click on that to load a virtual drive containing the Pulsar
application. Drag that application into your Applications folder. It is
ready to run.
Pulsar on Linux
Linux (x86) Pulsar |
Linux (ARM) Pulsar |
For a Linux machine, you need to determine whether you are running an Intel machine or an ARM machine. ARM Linux setups are incredibly rare and you would know if you had one. Click on the button below that matches your machine. This will download an AppImage file that will run Pulsar on any Linux distro.
With that said, we find it easier to install Pulsar on Linux via FlatPak. FlatPak is a universal installer that automatically configures itself to your distribution. It is Steam’s preferred method of distributing games on the Steam Deck, and we have found it to be quite useful. Unlike AppImage, a Flatpak applications is a sandboxed. That means it is more secure and more reliable than the AppImage version.
Configuring Pulsar
The first time that you open Pulsar, you will see two welcome windows like the ones shown below. These windows will keep popping up every time you open Pulsar, and will constantly get in the way. So we want to get rid of them. Make sure to uncheck the boxes Show Welcome Guide when opening Pulsar and Show the Change Log after an update. Then close these windows by clicking their tabs at the top of the window.
The next thing you should do is to make sure your whitespace is configured correctly. One of the most controversial aspects of Python is that it treats spaces and tabs (which are called whitespace, because they are invisible) 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. However, we must first configure Pulsar so that indentation is consistent across all of our files. First, open Pulsar. Then, open the Settings menu option; in Windows, it is under the File category, and in Mac, it is under Pulsar (and is named Preferences). In the settings window that opens, select the Editor category, and scroll down. First, check the boxes “Show Indent Guide” and “Show Invisibles” so that your settings match this image:
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 two ‘>’ characters next to each other. These are illustrated in the examples below.
Pulsar with Tabs (Bad) | Spaces Only (Good) | |
---|---|---|
![]() |
![]() |
Continue scrolling down. Make sure that the value in “Tab Length” is 4, and click on the value in “Tab Type”. This should open a drop-down menu. Select “soft”. This will make Pulsar automatically replace all Tabs you input with 4 spaces. After configuring, these two settings should look like this:
Alternative Editors
There are many other Python code editors out there, and everyone has their own preference. You are free to use whatever editor you want, so long as you have the license to use it. For example, some people really like Sublime Text. However, that program is not free, and therefore we cannot encourage its use in this class. But if you have paid for a license for this editor, you are free to use it.
The most obvious alternative to Pulsar is VSCode. In fact, Pulsar is a successor to Atom, and Microsoft discontinued Atom to focus work on VSCode. However, we can say from experience that VSCode is completely unsuitable for beginner Python programming. VSCode iolates the Python specification in serious ways, resulting in erroneous and confusing error messages. If you come to us with an error in VSCode, we will instruct you to uninstall that software.
Another thing to keep in mind is that many of the projects are done with partners. While you are free to use other editors, we recommend that you and your partner both use the same editor.
Using GitHub
We do not require the use of GitHub for this course, as it is a bit too advanced for many students. However, we know that some of you will use it anyway, particularly for sharing assignment code with your partner. Because of our academic integrity policy, we need to put strict rules on its use.
The free accounts that you get from github.com
are publicly viewable. That
means anyone can see them, and anyone can download code from them. This means
that if you put your code on GitHub, and another student downloads it, you will
be held liable for cheating, even though you may have no idea who this other
person is. In fact, any code we find in publicly visibile in GitHub will
constitute an academic integrity violation whether or not anyone copies it.
If you want to use a code repository, you should use the official Cornell GitHub instead. Any projects that you put here will be protected and cannot be accessed by other students. You will not be held liable for security leaks that are not your fault.
We know that this is inconvenient for students that would like to show code to prospective employers. However, there has been enough abuse of this in recent years that we have had to take a stricter approach to GitHub. We recommend that you share your code through a private repository or else work on another Python project in your own time.