How to Run Code in PyCharm Step by Step

Summarize this article with:
You wrote the code. Now what?
Knowing how to run code in PyCharm separates productive developers from those stuck clicking random buttons hoping something works.
PyCharm offers seven distinct methods to execute Python scripts. Each serves a different purpose.
Some developers never move past the context menu. Others master keyboard shortcuts and cut their workflow time in half.
This guide walks through every script execution method available in the JetBrains IDE. You’ll learn run configurations, gutter icons, terminal commands, and the Python console.
By the end, you’ll pick the right execution method for any situation without hesitation.
How to Run Code in PyCharm

Learning how to run code in PyCharm is the process of executing Python scripts within JetBrains’ integrated development environment using run configurations, keyboard shortcuts, or context menus.
You need this when testing scripts, debugging applications, or verifying code changes during development.
This guide covers 7 methods requiring 3-5 minutes and basic familiarity with the PyCharm IDE.
Prerequisites
Before running any Python script, confirm these requirements:
- PyCharm version: Community Edition 2023.x or Professional Edition installed
- Python interpreter: Python 3.8+ configured in your project
- Project setup: At least one .py file created in your project structure
- Time estimate: 3-5 minutes to complete all steps
Need to add a Python interpreter in PyCharm first? Do that before continuing.
If you haven’t configured your environment yet, learn how to setup PyCharm properly.
Step One: How Do You Run Code Using the Context Menu?
Right-click anywhere inside your Python file editor to access the context menu, then select “Run [filename]” to execute the script in the Run tool window.
Action
- Location: Right-click inside the code editor area
- Menu path: Run ‘[your_filename]’
- Result: Script executes; output appears in Run tool window at bottom of screen
Purpose
The context menu method works best for quick, one-off script execution without memorizing shortcuts.
PyCharm automatically creates a temporary run configuration when you use this method.
Step Two: How Do You Run Code Using Keyboard Shortcuts?
Press Ctrl+Shift+F10 (Windows/Linux) or Control+Shift+R (macOS) to instantly run the current Python file without touching your mouse.
Action
- First run: Ctrl+Shift+F10 (Windows/Linux) or Control+Shift+R (macOS)
- Re-run last script: Shift+F10 (Windows/Linux) or Control+R (macOS)
- Result: Console output displays in Run tool window
Purpose
Keyboard shortcuts provide the fastest execution method during active software development.
Once you run a script, Shift+F10 re-executes it instantly. Saves significant time during iterative testing.
Step Three: How Do You Run Code Using the Gutter Icon?
Click the green play icon in the gutter (left margin beside line numbers) next to any runnable code block like a main function or class definition.
Action
- Location: Green triangle icon in the left gutter area
- Click action: Select “Run ‘[filename]'” from the popup menu
- Result: Code executes; output shows in Run tool window
Purpose
The gutter icon appears automatically next to if name == 'main': blocks and test functions.
This visual indicator helps beginners locate exactly where execution will start. Also useful when your file contains multiple runnable entry points.
Want to step through code line by line instead? Learn how to debug in PyCharm for breakpoint-based execution.
Step Four: How Do You Run Code Using the Run Menu?
Access Run > Run from the main menu bar or press Alt+Shift+F10 to open a popup showing all available run configurations for your project.
Action
- Menu path: Run > Run from the top menu bar
- Shortcut: Alt+Shift+F10 opens configuration selector
- Selection: Choose your script from the popup list
Purpose
The Run menu provides access to all saved run/debug configurations in one place.
Best for projects with multiple entry points or when switching between different scripts frequently.
Step Five: How Do You Run Code Using the Run Widget?
The Run Widget sits in the top toolbar, displaying the currently selected configuration with a green play button for instant execution.
Action
- Location: Top-right area of the main toolbar
- Selection: Click dropdown to choose “Current File” or a saved configuration
- Execution: Click the green play icon to run
Purpose
The widget offers one-click execution without navigating menus. Always visible during coding sessions.
Step Six: How Do You Run Code in the Python Console?
Open Tools > Python Console to launch an interactive interpreter where you can execute code line by line or run selected code fragments.
Action
- Console path: Tools > Python Console from main menu
- Run selection: Highlight code, press Alt+Shift+E
- Result: Code executes in interactive console with immediate output
Purpose
The Python Console excels at testing code snippets, exploring APIs, and quick experimentation without running entire scripts.
Supports IPython if installed. Great for data analysis workflows.
Step Seven: How Do You Run Code Using the Terminal?
Open the integrated terminal window at the bottom of PyCharm and execute Python scripts using standard command-line syntax.
Action
- Terminal access: View > Tool Windows > Terminal (or Alt+F12)
- Command syntax:
python filename.pyorpython3 filename.py - Result: Output displays directly in terminal
Purpose
Terminal execution mirrors production environment behavior. Required for scripts needing command-line arguments or specific environment variables.
Also useful when working with virtual environments in PyCharm that need manual activation.
Verification
Confirm successful code execution by checking these indicators:
- Run tool window: Shows “Process finished with exit code 0” for successful runs
- Output panel: Displays expected print statements or return values
- Exit code: 0 means success; non-zero indicates errors
If your script produces no visible output, add a simple print("Script completed") statement at the end to verify execution.
Troubleshooting
Issue: No Python Interpreter Configured
Solution: Navigate to File > Settings > Project > Python Interpreter, click the gear icon, select “Add Interpreter” and choose your Python installation path.
Need packages? Learn how to install packages in PyCharm after configuring your interpreter.
Issue: Run Option Grayed Out
Solution: Verify your file has a .py extension. Check that PyCharm recognizes the file as Python by looking for syntax highlighting.
Sometimes you need to create a new project in PyCharm with proper Python SDK configuration.
Issue: ModuleNotFoundError When Running
Solution: Check your working directory in Run Configuration settings matches your project root. Verify the module is installed in your active interpreter.
Missing libraries? See how to install libraries in PyCharm for package management.
Issue: Wrong Python Version Executing
Solution: Multiple Python installations can cause conflicts. Review how to change Python version in PyCharm to select the correct interpreter.
Alternative Methods Comparison
| Method | Steps | Best For |
| Context Menu | 2 clicks | Quick single-file runs |
| Keyboard Shortcut | 1 keystroke | Repeated execution during development |
| Gutter Icon | 1 click | Visual learners; multiple entry points |
| Run Menu | 2-3 clicks | Switching between configurations |
| Run Widget | 1 click | Persistent toolbar access |
| Python Console | 2 steps | Interactive testing; code snippets |
| Terminal | Type command | CLI arguments; production-like runs |
Choose keyboard shortcuts for speed during active coding. Use terminal when testing deployment scenarios or passing arguments.
Related Processes
After mastering script execution, explore these connected workflows:
- Version control: Connect PyCharm to GitHub for source control integration
- Testing: Run unit tests directly from PyCharm using pytest or unittest frameworks
- Code quality: Use code refactoring tools to improve your scripts before running
- Debugging: Set breakpoints and step through code when runs produce unexpected results
PyCharm functions as a complete web development IDE when building Python web applications with Django or Flask.
Consider implementing test-driven development practices to catch errors before manual script execution.
FAQ on How To Run Code In Pycharm
What is the fastest way to run Python code in PyCharm?
Press Shift+F10 to re-run your last executed script instantly. For first-time runs, use Ctrl+Shift+F10 (Windows/Linux) or Control+Shift+R (macOS).
Keyboard shortcuts beat clicking through menus every time.
Why is my Run option grayed out in PyCharm?
PyCharm needs a configured Python interpreter to execute scripts. Check File > Settings > Project > Python Interpreter.
Also verify your file has a .py extension and exists within a recognized project structure.
How do I run only selected code in PyCharm?
Highlight the code fragment you want to execute. Press Alt+Shift+E to run the selection in the Python Console.
This method works perfectly for testing specific functions or code blocks without running entire scripts.
Can I run Python scripts with command-line arguments in PyCharm?
Yes. Open Run > Edit Configurations, select your script, and enter arguments in the Parameters field.
Alternatively, use the integrated terminal and run python script.py arg1 arg2 directly.
What is the difference between Run and Debug in PyCharm?
Run executes your script straight through to completion. Debug pauses at breakpoints, letting you inspect variables and step through code line by line.
Use Debug when troubleshooting unexpected behavior.
How do I run a specific Python file when my project has multiple scripts?
Right-click the file you want in the Project tool window and select “Run”. PyCharm creates a dedicated run configuration for that specific file.
Switch between configurations using the Run Widget dropdown.
Why does PyCharm say “No Python interpreter configured” when I try to run code?
Your project lacks an assigned interpreter. Navigate to Settings > Project > Python Interpreter and add one.
You can use system Python, a containerized environment, or create a new virtual environment.
How do I stop a running script in PyCharm?
Click the red Stop button in the Run tool window or press Ctrl+F2. This terminates the process immediately.
For infinite loops or hung scripts, this is your quickest exit.
Can I run Python code in PyCharm Community Edition?
Absolutely. PyCharm Community Edition supports all standard Python execution methods including run configurations, console, terminal, and debugging.
Professional Edition adds web framework support but isn’t required for running Python scripts.
How do I see print output when running code in PyCharm?
All print() statements appear in the Run tool window at the bottom of the screen after execution.
If the window isn’t visible, press Alt+4 or go to View > Tool Windows > Run.
Conclusion
Mastering how to run code in PyCharm transforms your Python development workflow from clunky to seamless.
You now have seven execution methods at your disposal. Context menus for quick runs. Gutter icons for visual clarity. The Run Widget for one-click access.
The integrated terminal handles command-line arguments. The Python Console tackles interactive testing. Run configurations manage complex projects with multiple entry points.
Start with Shift+F10 for re-running scripts. It becomes muscle memory fast.
When errors appear, check your interpreter settings first. Most execution failures trace back to misconfigured environments or missing dependencies.
Pick one method today. Practice it until automatic. Then add another to your toolkit.
- What Is Agentic Coding? The Next AI Dev Workflow - April 10, 2026
- From Setup To Monitoring: Why A DMARC Service Matters - April 10, 2026
- 4 Scalable Hosting Providers for Growing Small Business Websites - April 9, 2026







