How Do I Run a Selected Code in Pycharm?

Running Code in PyCharm

To run code in PyCharm, use the keyboard shortcut "Shift+F10". You can also right-click the file in the project view and select "Run". Alternatively, click the green arrow icon in the toolbar to run the current file and any previously executed files.

Running Specific Parts of a Python File

In PyCharm Professional edition, go to "View | Scientific mode". This enables code cells using "#%%". Place code after the delimiters to define cells.

In PyCharm Community edition, use the "PyCharm cell mode" plugin for similar functionality since Scientific mode is only in Professional.

Running Scripts

To run scripts, open the file in the editor or select it in the Project tool window then choose "Run" from the context menu or press "Ctrl+Shift+F10".

Passing Command Line Arguments

To pass command line arguments in PyCharm 2019.1+, click "Run" -> "Edit Configurations" from the menu bar. The Solver configuration PyCharm creates automatically is temporary.

Click "Run/Debug configurations" to see available commands and existing configurations. More run/debug options are under "More Actions" including "Run with Coverage" and "Profile".

Leave a Comment