Right-click the open file and choose Run. That’s all it takes. PyCharm picks up the project interpreter, executes the script and prints the output in the Run tool window, and you never have to build a run configuration by hand first.
JetBrains documentation says any executable script launches this way, since PyCharm creates a temporary run configuration the first time you run it.
One detail catches people later. A configuration created from the context menu or Ctrl+Shift+F10 uses the folder that contains the script as its working directory, not the project root, and that setting decides where relative file paths resolve.
How to Run a Python File in PyCharm

Right-click the open file and choose Run, or click the green Run icon in the toolbar. Both do the same thing. The script goes through the project interpreter and the output lands in the Run tool window.
No configuration has to exist beforehand. JetBrains documentation states that any executable script runs without one, because PyCharm creates a temporary run/debug configuration for you.
You do need a project, though. If the folder isn’t one yet, set up a new project so the file has an interpreter to run against.
Ways to start a run
Several launch paths work with zero setup. The context menu is the obvious one: right-click an open file in the editor and choose Run followed by the file name. If you’d rather not touch the menu, click the Run icon in the left gutter next to the main clause and pick Run. Shift+F10 launches whichever configuration the Run widget currently shows. The widget itself also works once you select Current File in the configuration list and click Run.
Code cells add one more route. Split a file with comment lines that start with #%%, click Run in the gutter beside a fragment, and PyCharm executes that cell in the Python Console.
Shift+F10 only repeats the selected configuration. In a fresh project with nothing selected, use the context menu instead.
First run from a new file
- Right-click the project folder, choose New, then Python File, and name it.
- Type a line that prints something, such as print(“Hello”).
- Right-click inside the editor and choose Run with the file name.
- Read the Run tool window. A clean finish ends with “Process finished with exit code 0”.
The second run is faster. The temporary configuration now sits in the Run widget, one click or one shortcut away.
Keyboard Shortcuts for Running Code in PyCharm
On the default Windows and Linux keymap, Shift+F10 runs the selected configuration, Ctrl+Shift+F10 runs the file open in the editor, and Shift+Alt+F10 opens a popup where you pick a configuration. The macOS keymap uses Ctrl+R, Ctrl+Shift+R and Ctrl+Alt+R for those same actions.
| Action | Windows / Linux | macOS |
|---|---|---|
| Run the selected configuration | Shift+F10 | Ctrl+R |
| Run the file open in the editor | Ctrl+Shift+F10 | Ctrl+Shift+R |
| Pick a configuration, then run | Shift+Alt+F10 | Ctrl+Alt+R |
| Debug the selected configuration | Shift+F9 | Ctrl+D |
According to the JetBrains Guide, the Shift+Alt+F10 popup lists permanent and temporary configurations. Press the right arrow on an entry to choose Run, Debug, Coverage or Profile, or to edit and delete it.
Whatever you select in that popup becomes the active configuration, so the plain run shortcut repeats it right away.
Why tutorials disagree on the shortcut
JetBrains’ PyCharm 2022.2 and 2023.2 help pages name Ctrl+Shift+F10 for running the current file. The current page lists Shift+F10 together with the Current File entry in the Run widget.
Both work. The PyCharm 2026.1 Help still documents Ctrl+Shift+F10 as the shortcut that creates a configuration for the open file.
macOS is messier. Keymap references list Ctrl+Shift+R for running the open file on the default macOS keymap, while the IntelliJ IDEA Classic keymap uses Cmd+Shift+F10, which explains the forum answers that give it.
Skip the guesswork. Open Settings, Keymap (Preferences on macOS) and search for the action named Run context configuration. The binding shown there is the one your install uses, and you can reassign it on the same screen.
Running code is a small slice of what the keymap covers. The full list of PyCharm keyboard shortcuts is worth a skim once.
Which Python Interpreter Does PyCharm Use to Run Code?
PyCharm runs the script with the interpreter set for the project, unless the run configuration names a different one. JetBrains documentation states that at least one Python interpreter must be configured before PyCharm can work with Python code.
Each interpreter entry points at a Python executable on your system. To change it, open Settings, Python, Interpreter, or use the Python Interpreter selector in the status bar.
PyCharm 2026.2 documentation lists the environment types it can create or reuse.
| Type | How PyCharm sets it up | Documented condition |
|---|---|---|
| Virtualenv | Generate a new one or select an existing one | Pick a base interpreter and an empty folder for the new environment |
| Conda | New or existing environment; PyCharm detects the conda installation | If detection fails, point to the conda executable by hand |
| Poetry | Pick Poetry as the environment type | If the executable is missing, Install poetry via pip is offered |
| uv | Pick uv; PyCharm detects the installation | Listed next to pipenv and hatch as a local environment option |
| Docker | Remote interpreter through Docker or Docker Compose | Listed under PyCharm Pro |
| WSL | Linux interpreter on a Windows machine | Windows only, listed under PyCharm Pro |
For a step-by-step walkthrough of the dialog, see this guide to adding a Python interpreter in PyCharm.
Choosing between virtualenv, Conda and Poetry is a project question more than a PyCharm one. A comparison of venv, Conda and Poetry covers the trade-offs.
There’s one limit worth knowing. When PyCharm drops support for an outdated Python version, any interpreter built on it gets marked unsupported. Create a new environment on a current version and switch to it.
How to Create and Edit a Run Configuration
Open Run > Edit Configurations, click Add New Configuration, choose Python, then fill in the script path and interpreter and click OK. PyCharm stores the result and shows it in the Run widget.
Temporary and saved configurations
The first time a script runs, PyCharm builds a temporary run/debug configuration automatically, per the PyCharm 2026.1 Help. Editing it from the Run widget turns it into one you can keep.
By default, PyCharm stores run configuration settings in .idea/workspace.xml. The Store as project file option in the dialog exists for configurations that team members should receive.
Fields that change how the script runs
The script path or module name tells PyCharm what to execute, either a .py file or a module. Script parameters are the arguments handed to the script, separated by spaces. The interpreter field applies to this configuration alone, and environment variables work the same way, set for this configuration only.
The working directory is the folder the script treats as current. Last, Run with Python console starts the script inside the Python Console instead of a plain process.
The working directory field catches people out. When PyCharm creates the configuration through Ctrl+Shift+F10 or the Run entry in the context menu, the working directory is the folder that contains the script.
So a script that opens data.csv looks for it next to the script, not in the project root. If the file lives elsewhere, change the field.
Reading Output in the Run Tool Window
The Run tool window shows everything the script prints, and its last line reports the exit code. Each run gets a tab named after the run configuration that launched it.
Rerunning replaces the content of that tab. Pin the tab to keep the output across reruns, per the PyCharm 2026.1 Help (Advanced Settings also has an option to pin configurations by default).
Toolbar controls
- Rerun (Ctrl+F5) stops the current process and starts it again.
- Stop (Ctrl+F2) sends a soft kill on the first click, so the script can catch SIGINT and shut down cleanly. Windows emulates Ctrl+C.
- Close (Ctrl+Shift+F4) closes the tab and terminates the process.
- Clear All wipes the output pane.
- The stack trace arrows (Ctrl+Alt+Up and Ctrl+Alt+Down) move the caret to the matching line in the source.
A script that wraps its loop in try/except KeyboardInterrupt treats the first Stop click like Ctrl+C in a terminal. Without that handler, Python raises the exception and prints a traceback.
Scripts that call input() read from this window too. Click inside the pane and type the answer.
Reading the exit code
Exit code 0 means the script ran to the end. An unhandled exception gives code 1, with the traceback printed above the exit line.
Values such as -1073740791 (0xC0000409) are a different animal. They come from the operating system, not from Python, and arrive without a traceback.
A Stack Overflow answer from 2020 reports that switching on Emulate terminal in output console, in the configuration’s options, brings the error details back. A JetBrains support thread on the same code suggests a different check: run the command shown in the Run window from a terminal outside the IDE, because the code comes from Windows, not from PyCharm.
Running Code in the Python Console and Terminal
The Python Console runs code line by line in a live session, so variables survive between commands. The Terminal runs python script.py in a shell, like any command line.
Execute selection and Run with Python Console
To test a few lines, highlight them, right-click, and choose Execute Selection in Python Console, or press Alt+Shift+E.
For a whole file, tick Run with Python console in the run configuration, and the script loads into the console instead of a plain process. Its variables stay available there after the script finishes. If you’re juggling several scripts, click New Console to give each one its own session.
By default the console uses the Python interpreter defined for the project, according to the PyCharm 2026.2 Help. JetBrains names code completion, code analysis and quick fixes as the main reasons to prefer it over a bare shell.
Terminal as a command-line alternative
Press Alt+F12 or choose View > Tool Windows > Terminal. If you want a refresher, this guide shows how to open the terminal in PyCharm step by step.
The Terminal starts in the project root by default. A run launched from the editor’s context menu starts in the script’s own folder, so the same relative path can resolve differently in each.
For a project interpreter that is a virtual environment, the Activate virtualenv setting runs the activation for you. PyCharm 2026.2 documentation lists two terminal engines, Reworked 2025 (the default since 2025.2) and Classic, so the settings page may look different on your build.
Reach for the Terminal when the script needs pipes, redirects or shell tools. For everything else, Run is shorter.
| Method | Session | Variables after the run | Pick it for |
|---|---|---|---|
| Run | Fresh process | Gone when it ends | Whole-script runs |
| Run with Python console | Console session | Stay in the console | Inspecting results |
| Execute Selection | Existing console | Stay in the console | Testing a few lines |
| Terminal | Shell session | Gone when it ends | Pipes, flags, redirects |
Run Versus Debug in PyCharm
Run executes the script to the end and prints the output. Debug starts the same configuration with the debugger attached, so breakpoints pause execution and variables become inspectable.
Run ignores breakpoints, finishes the script and reports an exit code. Debug stops at each breakpoint and opens the Debug tool window, which has panes for frames, variables and watches plus a Console tab.
To start, click Debug next to Run in the toolbar. To set a breakpoint, click the gutter beside the line.
The inline debugger shows variable values right in the editor once a breakpoint is hit. Step over moves one line at a time, and Resume continues to the next breakpoint, per the PyCharm 2026.2 Help.
The PyCharm 2023.1 tutorial adds one default worth knowing. The debugger halts on any exception your code does not catch, marked by a breakpoint icon with a lightning bolt.
A breakpoint on a line that never executes lets the script run straight through. The same happens if you launch with Run instead of Debug.
Plain Run is enough when you only need the output or the exit code. For the full debugger toolkit, see this walkthrough on debugging code in PyCharm.
Fixing Errors When Code Will Not Run in PyCharm
Most failed runs come down to the interpreter, the working directory or the run configuration, with the odd crash outside Python on top. The table maps each symptom to its fix.
| Symptom | Likely cause | Fix |
|---|---|---|
| No Python interpreter configured for the project | None set for this project | Add one under Settings > Python > Interpreter |
| ModuleNotFoundError | Package sits in another interpreter, or a local file shares its name | Install into the project interpreter, or rename the file |
| FileNotFoundError on a relative path | Working directory is not where the file lives | Set Working directory in the run configuration |
| Output from the wrong script | Shift+F10 repeated a different configuration | Select Current File or the right configuration |
| Negative exit code, no traceback | Crash outside Python code, reported by Windows | Run the same command in a terminal outside PyCharm, or turn on Emulate terminal in output console |
No interpreter configured
PyCharm shows this message with a Configure Python Interpreter link, and Stanford’s CS106A setup guide points users to that link. A University of Greenwich support post lists the usual causes. Python is not installed, or no path was given when the project was created.
Fixing it takes one step in Settings. If no interpreter exists yet, create a virtual environment in PyCharm and select it.
ModuleNotFoundError
The error means the interpreter that ran the code could not find the module, according to the Python Developer Tooling Handbook. In PyCharm the usual culprit is a package installed with pip in a system interpreter while the project uses a virtual environment.
A JetBrains support answer gives the check: open Settings, Python, Interpreter and look for the package in that list. If it is missing, install the package through the interpreter settings so it lands in the right environment.
Two traps are easy to miss. The import name can differ from the install name (scikit-learn imports as sklearn), and a file of your own named like the package shadows the installed one.
For a FileNotFoundError, check the working directory instead. Print os.getcwd() at the top of the script and compare it with where your file lives.
Running Code in PyCharm FAQ
Does the free version of PyCharm run code the same way as Pro?
Yes, for local scripts. Since PyCharm 2025.1, Community and Professional are a single unified product. Core functionality, including Jupyter Notebook support, is free, and a Pro subscription adds more features. The Run menu, shortcuts, run configurations and Run tool window behave identically. JetBrains documentation lists SSH, Docker, Docker Compose and WSL interpreters under PyCharm Pro. PyCharm Community 2025.2 was the last standalone Community release. See this comparison of the Community and Professional editions for the older split.
Can I run several instances of one run configuration at once?
Yes. Click Modify options in the configuration dialog and tick Allow multiple instances (the PyCharm 2022.2 Help calls it Allow parallel run).
With the box cleared, PyCharm offers to stop the running instance and start a new one.
How do I share a run configuration with my team?
Tick Store as project file in Edit Configurations. Without it, PyCharm keeps the settings in .idea/workspace.xml.
A project file travels with the repository, so teammates get the same script path, parameters and environment variables. The default location is .idea/runConfigurations. If your team does not share the .idea folder, save the file to another folder inside the project.
How do I run pytest tests in PyCharm?
Right-click a test file or a single test function and choose Run, the same way you run a script. PyCharm builds a test run configuration for the chosen runner, pytest or unittest.
The default runner sits under Settings, Python, Tools, Integrated Tools. This guide to running pytest in PyCharm covers the setup in detail.
Choosing a Daily Default for Running Code in PyCharm
The Current File entry in the Run widget is the best default for running code in PyCharm, because Shift+F10 then follows whichever file is open. It needs no saved settings and no interpreter changes.
The approach stops working when a script needs the same arguments, environment variables or interpreter on every run. At that point a named run configuration stores the setup once. Snippets and shell tools belong in the Python Console or the Terminal, not in a saved configuration.
That order adds setup only when the previous step fails, so each script costs the least effort that still works.
Saving has a price. Every script gains one more configuration to maintain, stored in .idea/workspace.xml by default.
Keymap defaults and help pages have shifted between PyCharm versions, so recheck the bindings after a major upgrade (verified against the PyCharm 2026.2 documentation, October 2026).
- Build or Buy an AI Chatbot for E-commerce: The Costs Nobody Budgets For - October 24, 2026
- How to Run a React App in VS Code Step by Step - October 23, 2026
- Transactional or marketing email: which messages your app should send itself - October 23, 2026



