CS110: Fall 2021

Intro to Computer Programming with Python

CS110: Fall 2021

Lessons > 17. Working with the Terminal / Command Prompt

Today in lecture, we will learn how to work with the Terminal (Mac) or Command Prompt (Windows) in order to (a) run python files and (b) install third-party python modules/packages using PIP. There are no pre-recorded videos today.

Today's Activities

For today, please do the following:

1. Download the Exercise Files

Exercise Files

2. Review the Slides

  1. Intro to the Command Line & PIP

3. Watch the Lecture Video(s)

Link Title Type Duration
Video 1 Live Lecture (Part 1) lecture 37:56
Video 2 Live Lecture (Part 2) lecture 9:24

4. Review the Command Line Cheatsheet

For your convenience, we have made you a little cheatsheet to help you get familiar with the command line. Django Girls is a good resource. Note: you will not be tested on this or anything, but navigating the command line can be useful.

  DOS (Windows) Shell (Mac / Linux)
What directory am I in? > cd $ pwd
Change directories > cd $ cd
List files & directories > dir
> tree # lists subdirectories
$ ls
$ ls -l
Navigate to parent directory > cd .. $ cd ..
Navigate into child directory > cd cs110 $ cd cs110
Navigate into descendant directory > cd lectures\lecture_03 $ cd lectures/lecture_03
Navigate to sibling directory > cd ..\lecture_02 $ cd ../lecture_02
Navigate to ancestor directory > cd ..\..\ $ cd ../../
Navigate to home directory   $ cd
Command history > doskey /HISTORY $ history

Other optional commands you may find useful…

  DOS (Windows) Shell (Mac / Linux)
Create a new file > echo . > my_file.txt $ echo . > my_file.txt
$ touch my_file.txt
Append to a file > echo "some text" >> my_file.txt $ echo "some text" > my_file.txt
Save history to a file > doskey /HISTORY > my_history.txt $ history > my_history.txt
Move a file > move my_history.txt Documents/. $ mv my_history.txt Documents/.
Make a folder > mkdir my_folder $ mkdir my_folder
Delete a file > del my_history.txt $ rm my_history.txt
Delete a folder > rmdir my_folder $ rm -r my_folder

5. If you have a Windows machine

If you have a Windows Machine, there are (at least) two ways to ensure that python3 and PIP work when you run them from the command prompt. Note: this is an either -or- thing (e.g. you shouldn’t have to do Option 2 unless Option 1 doesn’t work).

Option 1: Run the Installer Again

In our opinion, the easiest way to get python to work on your command prompt is to run the Python3 installer again and make sure that the checkbox at the very bottom that says Add Python 3.x to PATH is checked:

Option 2: Go to System Preferences and Manually Add the PATH

To go this route, you will complete three steps:

Step 1

Search for Edit the System Environment Variables (see below):

Step 2

You will then click the Environment Variables button in the Control Panel:

Step 3

Finally, you will add the \Scripts folder in their Python installation to their path (see 3rd screenshot). This looks different on everyone’s machine, so you will have to make sure that this PATH corresponds to your Python3 installation. This screenshot below is pertains to Cooper’s path (one of the course TAs), but yours will look different.