How can I run the current file in PyCharm
Solution 1
As it turns out, the action I was seeking is "Run context configuration" (or "Debug context configuration" for debugging). The default key binding on Windows is ctrl+shift+f10, or ctrl+option+R on Mac, as Ev. Kounis pointed out, although you can bind it to any key you like.
These settings can be found under the "Other" section in File->Settings->Keymap. The easiest way to find them is to simply use the search box.
Solution 2
Just right click on the tab of your file and click run "file name" or you can press CTRL+shift+F10
Solution 3
The key combination you are looking for is Ctrl + Shift + F10. This will run the current script with current being the one displayed in the viewer.
Solution 4
There are several alternatives:
- Run context configuration from editor shortcut:
Mac: ⌃⇧R
Windows/Linux: Ctrl + Shift + F10
- You can right click on the file, and then run
Run 'filename'
.
- You can also run the shortcut to
Find Action
and then type run:
Mac: ⇧⌘A
Windows/Linux: Ctrl + Shift + A
- If the current file was just run, you can simply use the Run shortcut:
Mac: ⌃R
Windows/Linux: Shift + F10
References:
PyCharm Shorcuts for Windows and Linux
Solution 5
Keyboard shortcuts can be different on some machines. So you can just click right key on mouse and then "Run "(also you can select part of code and do the same)
alvion
Updated on October 29, 2020Comments
-
alvion over 3 years
How can I run the current file in PyCharm? I would like a single hotkey that will execute the current file (whether normal file, scratch file, or scratch buffer) using the project default python interpreter. I would like to NOT have to create a custom run configuration, but just launch with the default Python configuration. Is such a thing possible?
-
alvion about 7 yearsThis will give me the option to run the current file as one of the items in the list, but won't do it immediately.
-
John Paraskevopoulos about 7 yearsyou're not specifying what keymap you have, neither your OS. You can't ask for shortcuts for an IDE without specifying any of these. So yes
Ctrl+Shift+F10
works for you, but won't work for other cases/people. That's why I pointed you to see/set your own shortcut. -
alvion about 7 yearsThat's true of course. The way key bindings work in PyCharm is that you associate a key with an action, so if there is an existing action that I could bind the key to, that would be an acceptable answer. The reason I didn't ask for an action specifically is that I thought that the answer may involve a macro, a plugin, etc. As it turns out that is not the case, and I will show in my own answer, based on the shortcut that Ev. Kounis suggested.
-
John Paraskevopoulos about 7 yearslol sure ok mark your answer as correct. then someone who runs linux/macos or pycharm has imported other keymappings can mark your answer as not useful because ctrl+shift+f10 will not work on their machine ^^
-
alvion about 7 yearsThe correct answer is to use "Run in Context", which I stated clearly in my answer. I only mentioned "ctrl+shift+f10" in passing as an example. Your answer is utterly and obviously wrong, so I don't know what you're complaining about.
-
John Paraskevopoulos about 7 yearscan you point me where exactly I can find the "Run in Context" shortcut then? I'm trying ctrl+shift+f10 on my computer and nothing happens..
-
alvion about 7 yearsFile->Settings->Keymap. Then type "Run Context Configuration" in the search box. Choose that. (It's under "Other", and very difficult to find otherwise). The exact language was wrong in the answer I provided, though typing "Run in Context" in the search box would take you to exactly the right entry. I've updated the answer to provide the exact language.
-
Zeeshan Ahmad Khalil about 5 yearsI was looking for that method in the whole internet. I just forgot that we can right click on tabs in pycharm.
-
Timus over 3 yearsWelcome to SO! When you are about to answer an old question (this one is over 3 years old) that already has an accepted answer (that is the case here) please ask yourself: Do I really have a substantial improvement to offer? If not, consider refraining from answering.
-
Cees Timmerman over 3 yearsAlt+Shift+F10 in PyCharm 2020.3.