Integrated Development Environment (PyCharm)

JetBrains PyCharm is a suitable IDE for the Python assignments. The Community Edition is free and sufficient for this course.

Install PyCharm by following the official guide: PyCharm Installation Instructions

Note

The screenshots below are from Windows. On macOS the menu path is typically PyCharm > Settings instead of File > Settings.

Prerequisites

Before you start in PyCharm, make sure you have:

  • downloaded or cloned the repository cas-assignment

  • created the conda environment called cas (as described in Python Installation)

Open the assignment as a PyCharm project

  1. Start PyCharm.

  2. Click Open (or File > Open).

  3. Select the folder cas-assignment (the repository root), then confirm.

    _images/pycharm_setup_1.png

Configure the Python interpreter (conda environment cas)

PyCharm must use the conda environment cas to find the required libraries.

  1. Open the settings:

    • Windows/Linux: File > Settings…

    • macOS: PyCharm > Settings…

    _images/pycharm_setup_2.png
  2. In the left sidebar, go to Python > Interpreter.

    _images/pycharm_setup_3.png
  3. If cas is already available in the interpreter dropdown, select it. Otherwise add it:

    • click Add Interpreter

    • choose Add Local Interpreter…

    _images/pycharm_setup_3.png
  4. In Add Python Interpreter:

    • select Select existing

    • set Type to Conda

    • set Environment to your cas environment folder, for example:

      • Windows: C:\Users\<username>\miniconda3\envs\cas

      • Linux/macOS: /home/<username>/miniconda3/envs/cas

    • click OK

    _images/pycharm_setup_4.png
  5. Back in Python > Interpreter, confirm that:

    • the selected interpreter points to .../envs/cas/...

    • you see many installed packages in the list

    Then click OK to close the settings.

    _images/pycharm_setup_5.png

Verify your setup in PyCharm

  1. Make sure the run configuration cas is selected in the top bar.

  2. With cas/test_installation.py open, click the green Run button.

    _images/pycharm_setup_9.png

Note

The installation test requires the file data/planning/pelvis_ct.nii.gz. If it is missing, cas/test_installation.py will stop and print instructions on where to place the file.

Download and copy the file by following Assignment Environment Setup.

Important

Before running any assignment code, make sure the cas run configuration is selected. Otherwise PyCharm may run using a different interpreter.

Troubleshooting (most common issues)

  • ImportError / ModuleNotFoundError Verify that Python > Interpreter points to envs/cas and that the run configuration uses the same interpreter.

  • File not found (relative paths to data) Verify that the run configuration Working directory is set to the repository root cas-assignment.