How can I run the current file in PyCharm

38,016

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

Screenshot

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:

  1. Run context configuration from editor shortcut:

Mac: R

Windows/Linux: Ctrl + Shift + F10

  1. You can right click on the file, and then run Run 'filename'.

enter image description here

  1. You can also run the shortcut to Find Action and then type run:

Mac: A

Windows/Linux: Ctrl + Shift + A

enter image description here

  1. If the current file was just run, you can simply use the Run shortcut:

Mac: R

Windows/Linux: Shift + F10


References:

PyCharm Shorcuts for Mac OS X

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)

Share:
38,016
alvion
Author by

alvion

Updated on October 29, 2020

Comments

  • alvion
    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
    alvion about 7 years
    This 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
    John Paraskevopoulos about 7 years
    you'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
    alvion about 7 years
    That'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
    John Paraskevopoulos about 7 years
    lol 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
    alvion about 7 years
    The 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
    John Paraskevopoulos about 7 years
    can 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
    alvion about 7 years
    File->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
    Zeeshan Ahmad Khalil about 5 years
    I was looking for that method in the whole internet. I just forgot that we can right click on tabs in pycharm.
  • Timus
    Timus over 3 years
    Welcome 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
    Cees Timmerman over 3 years
    Alt+Shift+F10 in PyCharm 2020.3.