Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyCharm Run and Debug

PyCharm Run and Debug

PyCharm provides powerful run and debug tools that help developers execute Python code efficiently and troubleshoot problems. This section details environment configuration, script execution, and debugging techniques.


Configure the runtime environment

Set the Python interpreter

**Open interpreter settings:** Settings -> Project -> Python Interpreter (Windows/Linux: Ctrl+Alt+S, Mac: Cmd+,).

Choose the interpreter:

Install dependency packages:


Configure run parameters

Open run configuration:

**Add a Python configuration:** click + -> select Python

Key parameters:

**Save the configuration:** click Apply -> OK.


Run a Python script

Run a single file

Method 1: right-click to run:

Method 2: run from the toolbar:

Method 3: run with a shortcut:

Run a module (e.g., Flask/Django)

**Configure module run:** choose the module name instead of a script path in the run configuration.

For example:

Run a module with parameters:



# Example running Django development server

python manage.py runserver 0.0.0.0:8000

In the run configuration's "Parameters" field, enter: runserver 0.0.0.0:8000


Debug code

Set breakpoints

Add a breakpoint:

Breakpoint types:

Start debugging:

Variable watches

View variables:

Add a watch:

Debug control operations

Operation Shortcut (Win/Linux) Shortcut (Mac) Description
Step Over F8 F8 Execute the current line without entering the function
Step Into F7 F7 Enter the function to debug inside it
Step Out Shift + F8 ⇧ + F8 Execute the rest of the current function and return to the caller
Resume F9 ⌘ + F8 Continue running until the next breakpoint
Stop Ctrl + F2 ⌘ + F2 Terminate the debug session

Debug console

Interactive debugging:

  • Evaluate expression:

    • Select code → right click → 评估表达式(Evaluate Expression)

    • Or shortcut Alt + F8


    Advanced debugging techniques

    Remote debugging

    Configure a remote interpreter:

    • 文件 → 设置 → Python 解释器 → 添加远程解释器

    • Supports SSH, Docker, and Vagrant

    Debug remote code:

    • Breakpoints and debug operations are the same as in local debugging

    Multi-process debugging

    Child process debugging:

    • Check the option in the run configuration 在子进程中调试(Debug child processes)

    • Suitable for multiprocessing or subprocess Scenario

    Attach to process:

    • 运行 → 附加到本地进程(Attach to Local Process)

    • Select a running Python process


    Common Problem Solutions

    Q1: Breakpoints not working?

    • Check whether the interpreter matches the project environment

    • Make sure the code is saved (Ctrl + S)

    • Check whether the breakpoint is disabled (the breakpoint icon is gray)

    Q2: How do I debug unit tests?

    • In the test file, right-click -> 调试 '测试名'

    • Or use pytest / unittest Dedicated run configuration

    Q3: Variables show "Unknown" during debugging?

    • Optimize the code structure and avoid overly complex expressions

    • Use Watches Add watch variables manually


    Debug shortcuts

    Scenario Operation
    Quickly run the current file Shift + F10
    Start debugging Shift + F9
    Conditional breakpoint Right-click a breakpoint -> set condition
    View variable values During debugging, in the Variables panel
    Execute code temporarily Enter commands in the debug console
    Multi-process debugging Check the option in the run configuration Debug child processes