Right click -> run behaves differently than using the keyboard shortcut for this menu point (terminal vs 'Run' console) when "#!/usr/bin/env python" in file


I have a .py file and I want to run it in the "Run" console (the one with the "play" symbol. Not terminal and not python console). 

The file has "#!/usr/bin/env python" as the first line.

I right-click in the source code and select "Run 'scriptname'". This menu option also has a keybind to it, which can be set in the options as "Run context configuration". In my case I set it to F11 and it says "F11" in the right-click menu.

Issue: When I click on the "Run" in the right-click menu, PyCharm will run the script in the "Run" console like I want.

When I use the F11 shortcut that is set for exactly this menu point, PyCharm will run my script in the Terminal console (cmd.exe in my case).

I expect F11 to work exactly like it works when clicking with the mouse - why does it not do that?

- In the "Run configurations" for this script it does not matter, if I enable/disable "Emulate terminal in output console".

- If the right-click menu is open and I press F11, it works as expected.

- F11 is not bound to anything else and if I remove F11 from this right-click menu, F11 does not do anything.

- The first line of code (with #!/usr/...) has a green play button to its left. When I click it, a popup shows that says "Run File F11". If I then click it, it runs in Terminal. This menu/play button has no extra keybind in the options and seems to capture the key set for the right-click menu.

- The "if __name__ == "__main__":" also has a green play button next to it. Clicking it shows a popup with "Run 'scriptname' F11" (so exactly the same wording as in the right-click menu) and this runs the "Run" console as expected.

Is this inconsistent behavior intended? 

I personally do not want to run it in Terminal at all, though there seems to be no way to switch the behavior.


PyCharm 2020.3.1

1 comment
Comment actions Permalink


It seems to be known issue https://youtrack.jetbrains.com/issue/PY-45809

We already had multiple reports of this weird behavior. Please follow the issue for updates.


Please sign in to leave a comment.