How to Perform Debugging in Python PyCharm?
Last Updated :
20 Mar, 2024
Debugging is like finding and fixing mistakes in your computer code. PyCharm is a tool that helps with this, especially for Python code. It has special tools to make debugging easier. Whether you're new to programming or have been doing it for a while, getting good at debugging in PyCharm can make you a better coder. In this article, we will see how to Perform debugging in PyCharm.
Perform Debugging in Python PyCharm
When we run the Python code it shows two modes.
Now in this article let's focus on debugging the Python script file using PyCharm. While operating debugging there are some steps to be followed.
Step 1: Access Project Files in PyCharm
Open the project file and click the left button of the mouse. Then the following display will appear.

Step 2: Start Debugging in PyCharm
After clicking on a option Debug or press 'Shift+F9' , The Window firewall displays a pop-up message for debugging the project file for line by line compilation.

Step 3: Access Debugging Controls
After setting the permission then PyCharm starts debugging, the debugging executes till it reaches the break point, all the debugging controls will displayed on debug tool window. Lets take an example of a Python program in which we perform an operation of debugging in python.
Python3
import math
# Function to check if a number is prime
def is_prime(num):
if num <= 1:
return False
elif num <= 3:
return True
elif num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i <= math.isqrt(num):
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
# Take input from the user
user_input = int(input("Enter a number: "))
print("Checking if", user_input, "is prime...")
# Check if the input is prime
if is_prime(user_input):
print(user_input, "is a prime number.")
else:
print(user_input, "is not a prime number.")
-min-min.png)
Place a Breakpoints in the code by clicking on the number to suspend the program when Exception or its subclasses are thrown.

Step 4: Controls in PyCharm's Debug Tool Window
In the debug tool window, we will find various controls to help us navigate through our code while debugging. Now let us see some of the most commonly used tools.

- Step Over (F8): Executes the current line of code and moves to the next line. If the current line contains a function call, it will execute the entire function and pause on the next line after the function call.
- Step Into (F7): Moves the debugger into the function call, allowing you to step through the function's code line by line.
- Step Out (Shift+F8): Executes the remaining lines of the current function and returns to the function that is called.
- Resume Program (F9): Continues execution until the next breakpoint is encountered or if no break point was found it executes till the end of a program.
Step 5 : Inspect variable and Expression Evaluation in Debugging
We can inspect the values of variables in our code by hovering over them with our mouse or by using the "Variables" pane present in the debug tool window. Similarly we can also evaluate expressions and watch variables by typing them into the "Evaluate Expression" field in the debug tool window.
Step 6: Terminate Debugging
If any error was found simply edit the code in the editor window and PyCharm will automatically save the changes. After completing the debugging session terminate the session by clicking the "Stop" icon in debug tool window and or by pressing "Ctrl+F2".
Inline Debugging
Inline Debugging a technique where we can inspect the values of variables and expressions directly in our code. This is used for quick state of code at specific points during execution.
Inline DebuggingThe above indicated points are the inline debugging which shows expression directly in our code. By following Process we can performing the debugging in PyCharm and by debugging tools built into PyCharm, we can easily identify and fix issues in our code.
Similar Reads
How to perform testing in PyCharm?
PyCharm is a powerful integrated development environment (IDE) designed specifically for Python programming. Developed by JetBrains, PyCharm provides a comprehensive set of tools to streamline the development process, from code writing to testing and debugging. In this article, we will focus on the
4 min read
How to install Python and PyCharm on Mac
Installing PyCharm on macOS is a straightforward process. PyCharm is a popular Integrated Development Environment (IDE) for Python programming, and it offers both a free community edition and a more feature-rich professional edition. In this article, I will guide you through the steps to install PyC
2 min read
Debugging in Python with Pdb
The PDB module in Python gives us gigantic highlights for compelling debugging of Python code. This incorporates: Pausing of the programLooking at the execution of each line of codeChecking the values of variables This module is already installed with installing of python. So, we only need to import
6 min read
How to Install Python Pycharm on Linux?
Prerequisite: Python Language Introduction Python is a widely-used general-purpose, high-level programming language. It was initially designed by Guido van Rossum in 1991 and developed by Python Software Foundation. It was mainly developed for emphasis on code readability, and its syntax allows prog
2 min read
How to install Python Pycharm on Windows?
Python is a programming language that lets you work quickly and integrate systems more efficiently. We need to have an interpreter to interpret and run our programs. There are certain online interpreters like GFG-IDE, IDEONE CodePad, etc. Running Python codes on an offline interpreter is much more c
2 min read
How to Exit a Python Program in the Terminal
Exiting a Python program might seem like a straightforward task, but there are several ways to do it depending on the context and requirements of your script. Whether you want to gracefully shut down your application or terminate it immediately, knowing the right approach can help you manage your co
3 min read
How PyCharm supports Flask in Python?
Flask is a reliable framework for Python web applications and APIs. It is a well-liked option among developers due to its simplicity and adaptability. But to fully realize its potential, effective instruments are needed. PyCharm shows up as a powerful ally with a ton of capabilities designed specifi
4 min read
Debugging in R Programming
Debugging is a process of cleaning a program code from bugs to run it successfully. While writing codes, some mistakes or problems automatically appears after the compilation of code and are harder to diagnose. So, fixing it takes a lot of time and after multiple levels of calls. Debugging in R is t
3 min read
How to start with Selenium Debugging?
Debugging is essential for any developer, especially when working with Selenium for test automation. As your test scripts grow in complexity, the chances of encountering unexpected issues increase. Selenium debugging allows you to identify and resolve these issues by systematically analyzing your co
6 min read
Debugging decorators in Python
Decorators in Python are really a very powerful feature. If you are a web developer and you have used the Django framework or even some other development frameworks you would have already come across decorators. For an overview decorators are wrapper functions that wrap an existing function or a met
3 min read