Introduction to PyCharm

PyCharm is a so called "Integrated development environment" (IDE) for Python. In order to reproduce the instructions below you must have Python 3 and PyCharm installed on your computer:

Installation instructions

  • The ETH software kiosk offers PyCharm and Python 3 packed together for Windows computers (look for WinPython).

Else:

On Windows: If your computers fire wall complains during the next steps just press "Cancel" and ignore the message.

First steps with PyCharm: Create a Python project

If you start PyCharm you should see a window similar to this:

If you click Create New Project a new window opens:

  1. Enter a reasonable name for your first project in the Location field (here we use python_introductions)
  2. Select Python 3.5 in the second field named Interpreter.

The options will look very different on most machines, usually you see less choices, but if Python 3.5 was installed correctly it should show up here.

Create a new Python script

After the previous step you will see the new project in the left part of the PyCharm window. Now move the mouse to python_introductions and press the right mouse button to open a context menu. Then create your first Python script choosing "Python File" (not "File" !):

A small dialog box pops up and asks you to provide the name of the script you want to create. We demo the wage computation example from the course script, so we choose wage_computation.py as name (the extension .py indicates a Python script):

After this you see the new script listed in the project view on the left side.

Write and run a script

Use copy and paste to enter the wage computation script in the code editor on the right side of the window:

The first time you run a new script you have to start it from the context menu of wage_computation.py in the Project view (press the right mouse button for this):

Now you will see the output from the program in the lower part of PyCharm. Here you can enter the requested numbers followed by pressing the Enter key.

The first and last lines displayed in blue are written by PyCharm indicating which program is run and finally saying that the program was executed without any errors.

Edit and run cycle

Usually your program will not run on the first try. After you run a script the first time PyCharm remembers the scripts name and to run it again you can press the green triangle icon in the upper right part of the PyCharm window:

Recommodations

  • Create a fresh Python file for every script (=program) and exercise
  • Give it a reasonable name

Every time you run a script it will start in a fresh Python interpreter process. This means:

  • Everything from a previous run (same script or other script) is forgotten
  • In particular this applies to variables and import statements.
  • It is recommended to place import statements at the beginning of a script.