In this class, you will be writing code on your computer using an application called PyCharm. PyCharm is what is known as an IDE, or Integrated Development Environment, which means that it allows us to edit our code, browse our files, run our programs and debug them, all in the same place. It's one of the most popular Python IDEs in the world, and used extremely commonly in industry. This handout is intended to take you through installing PyCharm on your own computer.


Setting up

The Terminal

The Terminal, also sometimes called the Command Line or the Command Prompt on Windows, is a text-based interface for operating your computer. We'll be using it a bit throughout the quarter in order to run our programs, so make sure you know how to open the Terminal on your computer. This website explains how to find the Terminal application on your computer, as well as some further details on what you can do with it. You don't need to worry too much about those details just yet, although you're free to peruse them if you'd like. As we go through the quarter, we'll explore the capabilities of the terminal in much greater depth.

Installing Python

In order to be able to run Python programs on your computer, you need to install a Python Interpreter. An interpreter is a program that is capable of reading a .py file that you have written, and translating the Python code in that file to instructions that your computer can easily execute. Begin by downloading Python using the installers below.

Note: Even if you have previously installed Python before, you should go through this installation process to make sure that you have exactly the right version of Python installed that is required for this class.

Installing on a Mac

Note: Macs come with a version of Python installed, but this is an older version of Python (specifically, Python 2). CS 106A requires the use of Python 3, so make sure to follow these instructions even if you think you already have Python installed. If you require the use of Python 2 for other work, you can still install Python 3, which exists alongside Python 2 rather than replacing it.

  1. Open the downloaded Python installer file and follow the default instructions.
  2. Open up your terminal application.
  3. Type python3 and press enter. You should see something that looks like this:
  4.               
    Python 3.7.3 (default, Mar 27 2019, 09:23:15)
    [Clang 10.0.1 (clang-1001.0.46.3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
                  
                
Installing on Windows
  1. Open the downloaded file. Before installing, there should be an option that says "Add Python 3.7 in PATH". Make sure to check this box. Then, continue installing normally.
  2. Open up the command prompt.
  3. Type py and press enter. You should see something that looks like this:
  4.               
    Python 3.7.3 (v3.7.3:9a3ffc0492, Mar 27 2019, 09:23:15)
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
                  
                
Installing on Linux
Since there are so many different flavors of Linux, we cannot give detailed installation instructions. You should go ahead and install the most recent version of Python (3.7.3) using your friendly local neighborhood package manager, as well as the python3-tk package, which will install the graphical package that is used to visualize Karel.

Installing and Testing PyCharm

Installation

To get started, download and install the community version of PyCharm:

Testing PyCharm

Now that you have PyCharm downloaded and installed, open it up and follow the setup wizard, which allows you to choose some default settings. Feel free to install any additional plugins it suggests, although none will be necessary for this class.

PyCharm models a program as a 'project', which consists of one or more Python files, as well as any additional resources like images or text files. To get you familiar with working with projects in PyCharm, we've provided a sample project, which you can download here. To test out this project, and to gain familiarity with the PyCharm environment, download the sample project and open it in PyCharm (using the 'open' option on the first screen). Make sure to open the folder that is called pycharm_intro.

Important note: If you are on a Windows computer, you may have a second pycharm_intro folder nested inside the outer pycharm_intro folder. Make sure to open the innermost pycharm_intro folder.

Note: If you see notifications pop up in the bottom right hand corner that say "Invalid VCS root mapping" or "No R interpreter found" you can safely ignore them.

Now, follow the steps below to run the project in PyCharm:

  1. First, you need to configure the interpreter for the project, which essentially means that you want to specify the version of Python you'll be using to run your code. To do so, click 'configure Python Interpreter' at the top of your window:
  2. Then, select the dropdown at the top of the window and click 'show all'.
  3. Then click the + button at the bottom left corner.
  4. In the next window, make sure that you select the "System Interpreter" option in the left sidebar if it is not selected by default. Now, Python 3.7 should automatically be selected as the interpreter. If it is not, make sure to select Python 3.7 before proceding. Click 'OK', and save your progress. PyCharm might take a a minute or two to recognize your interpreter, but you should eventually be good to go.
  5. Once PyCharm has finished recognizing your interpreter (indicated by the progress bar in the bottom right corner), you should be ready to run your program! Click the green arrow in the top right of the window to run, and you should see a Karel window pop up, as well as a message from Karel in the bottom pane.
    • If you get an error saying "cannot run program", click "IntroKarel" in the top right>edit configuration>python interpreter> Python 3.7.
  6. Now, click the 'run' button in the Karel window to run the sample Karel program. You should see Karel draw a square made out of beepers on the screen. Congratulations! You've successfully set up PyCharm!