caring-goat-913
caring-goat-913

Reputation: 4049

How can I make PyCharm run the current file in the existing console?

If I try to run the file that I'm currently editing, it opens a new Python console window each time.

How can I make PyCharm run the current file using the console I already have open (i.e. the one that opens under Tools > Python Console...)?

I know there is an "Execute Selection in Console" feature, but I don't want to onerously select code. I want to run the entire file.

I'm trying to emulate the F5 run functionality in Spyder.

Edit:

Spyder also has a User Module Reloader (UMR) feature that reloads user-defined modules each time a file is run in the interactive console (as opposed to manually doing imp.reload()). Does PyCharm also have such a feature?

Upvotes: 5

Views: 3357

Answers (3)

TheDronist
TheDronist

Reputation: 78

In PyCharm 2023.2.2, on Linux:

(Menu File >>) Settings >> Build, Execution, Deployment >> Console >> Use existing console for "Run with Python Console"

This works if you execute your code files in the Python Console, which can be a python shell or an ipython shell depending on your settings. (e.g. Run Menu >> Edit Configurations>> Modify Options >> "Run with Python Console"

Upvotes: 0

skr
skr

Reputation: 452

On Pycharm 2018.1.4 you have to select "Run File in Console" the first time you wish to run a file in the console. Subsequently, you have to select the green arrowhead or press Shift+F10. All subsequent runs after the first will be executed in the open python terminal.

Upvotes: 0

Rob
Rob

Reputation: 555

If I understand you correctly: Since PyCharm 2017.3 there is an action "Execute File in Console" which does exactly that. You can find it with Find action (Ctrl + Shift + A) and execute currently selected file.

Upvotes: 2

Related Questions