The class will be using PyCharm as its Python programming environment. Here’s some instructions on how to install it.
Thanks to the CS106A team for these instructions; especially Brahm Capoor for typing up this handout for 106A and allowing us to use it for 106AX, and Nick Parlante, Jason Chen, Elyse Cornwall, and Ben Yan for their additional help and refinement.
We've spent most of the past few weeks coding in JavaScript. That meant that we were able to type up our code in a simple editor knowing that code would be referenced by an HTML page and executed when the HTML was loaded. Now that we're transitioning to a use Python for a bit, we need a new development environment for that. That development environment is 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 online document is intended to take you through the installation process so you can get PyCharm on your own computer.
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. Select the link corresponding to your operating system and download the latest version of Python 3.
When you open the file below, check the box that says “Add Python 3.12.0 to PATH”. Otherwise, install normally.
Macs come with a version of Python installed already, but it is sometimes outdated. This ensures that you have the correct version of Python installed.
Use the black download button to get the Community version of PyCharm
here (Windows).
here (macOS).
If you’re using an M1 Mac, change
.dmg (Intel)
to .dmg (Apple Silicon)
.
When you're done,
open the .dmg
file and drag it to your Applications folder.
open the .exe
file and install with all the defaults.
At the end of the PyCharm installation process, open PyCharm, and you'll see a welcome screen:
Click the 'Customize' tab on the left and then click 'All Settings...' at the bottom:
In the Preferences window, click the 'Python Interpreter' tab, and you should see a screen like this:
If you have no interpreter selected, or the interpreter is not Python 3.12.0 (the one you just downloaded), click the drop-down and select 'Show All...'. You should see a screen like this:
Click the + button on the upper left, then click 'System Interpreter' in the sidebar. Depending on whether you've installed other versions of Python before, the latest version of Python may already be selected in the dropdown menu. If not, select the latest version Python that you downloaded and then click 'OK' and 'OK' again. I know this picture says python 3.10, but yours should say 3.12.0 in the dropdown menu. Please select that version:
You should now be on a window that looks like this (although the contents of your list might look different):
Click 'Apply' and then 'OK' again to be taken back to the welcome page. You're now ready to test PyCharm!
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 and running progams 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 (on Windows, you'll need to manually unzip it by opening it in Windows Explorer and selecting 'Extract All') and open it in PyCharm (using the 'open' option on the first screen). Whenever you open projects in PyCharm, open the folder directly containing the files you want to edit as opposed to just the files themselves. Upon opening the project, you should be greeted by a window that looks like this:
Click 'Project' in the top left or use the Alt + 1
shortcut to open the file explorer, and open
intro.py
to pull up the editor:
You aren't required to read or understand this code (although you will be able to very soon!) but note that this editor is where you'll be writing all your code this quarter. Now, to run your program, click 'Terminal' in the bottom left corner, which will pull up a new terminal pane in your PyCharm window:
We'll talk more about the terminal later in the quarter, but for now, know that the terminal is how you'll be running your Python programs throughout the quarter. To run your first Python program, type this into the terminal and press enter:
intro.py
You should see output that looks like this:
Now, type the following command into the terminal:
intro.py < YOUR NAME HERE >
For example, if your name is Elyse, you'd type python3 intro.py Elyse
. You can type your full
name if you'd prefer. You should now see output like this:
Congratulations! You're now done with the PyCharm setup process.
Our strong recommendation is to use Python 3.9 or later, which can be installed in parallel with other versions of Python. This is the only version of Python we'll be supporting in this class. You must use at least Python 3.6.
If there's another environment that you're more comfortable with, you may use it, but the course staff will only provide support for issues in PyCharm. You must not modify any configuration files provided in assignment starter code.
can't open file intro.py: No such file or directory
!
What does this mean?
This most often happens when you open the incorrect file or folder in PyCharm. In this case, make sure to open
the pycharm_intro
folder that directly contains intro.py
, rather than
intro.py
itself or a folder containing pycharm_intro
. On Windows computer, you may
have a folder called pycharm_intro
with another folder inside it called pycharm_intro
.
Make sure to open the inner folder.
To correct this error, open the 'File' menu and click 'Open'. Then, navigate to the correct
pycharm_intro
folder and open it.
To verify that you are in the correct folder, type ls
(that's a lowercase 'L') into your terminal
(the same place you type intro.py < YOUR NAME HERE >
).
This will show you a list of all the files in that folder, and intro.py
should be in this list.
This is likely caused by an issue with how you set up the interpreter. To fix this, click 'Configure Python Interpreter', and set up the interpreter by following these steps until the 'Testing Pycharm' section.
You might be using a slightly older version of MacOS. Try installing this version of PyCharm instead.
If you are using a relatively new Mac, you may need to download a different version of the community version of PyCharm. Un-install the version you have, and then when you redownload click the downloads dropdown and select "Apple Silicon":
You might have downloaded the professional version of PyCharm, which is paid. Instead, select the community version on the PyCharm site and download that version.
Try installing this version of PyCharm instead.
The default interactive shell is now zsh. To update your account to use zsh, please run `chsh -s /bin/zsh`
. What should I do?
That's just an innocuous message, don't worry about it!