MorningGlory
MorningGlory

Reputation: 339

PyCharm running Python file always opens a new console

I initially started learning Python in Spyder, but decided to switch to PyCharm recently, hence I'm learning PyCharm with a Spyder-like mentality.

I'm interested in running a file in the Python console, but every time I rerun this file, it will run under a newly opened Python console. This can become annoying after a while, as there will be multiple Python consoles open which basically all do the same thing but with slight variations.

I would prefer to just have one single Python console and run an entire file within that single console. Would anybody know how to change this? Perhaps the mindset I'm using isn't very PyCharmic?

Upvotes: 16

Views: 18635

Answers (6)

Siddhant Tanpure
Siddhant Tanpure

Reputation: 59

To allow only one instance to run, go to "Run" in the top bar, then "Edit Configurations...". Finally, check "Single instance only" at the right side. This will run only one instance and restart every time you run.

Upvotes: 2

nodarkside
nodarkside

Reputation: 172

I think that what you are looking for is the last option in this window; check it and it should work.

Settings -> Build, Execution, Deployment -> Console

enter image description here

Upvotes: 0

exan
exan

Reputation: 3925

Hi: If you are looking for re running the code again in the same python console everytime then you have to check the respective box in the Project settings as shown in image below.

enter image description here

Upvotes: 15

Pavel Karateev
Pavel Karateev

Reputation: 8495

There is a specific option in PyCharm 2018.2+: Settings | Build, Execution, Deployment | Console | Use existing console for "Run with Python console".

Run with Python console is an option you have enabled in the Run Configuration. Disable it if you don't need a Python console after a script execution:

enter image description here

Upvotes: 26

vishes_shell
vishes_shell

Reputation: 23484

You have an option to Rerun the program.

Simply open and navigate to currently running app with:

  • Alt+4 (Windows)
  • +4 (Mac)

And then rerun it with:

  • Ctrl+R (Windows)
  • +R (Mac)

Another option:

Show actions popup:

  • Ctrl+Shift+A (Windows)
  • ++A (Mac)

And type Rerun ..., IDE then hint you with desired action, and call it.

Upvotes: 0

Steven
Steven

Reputation: 854

One console is one instance of Python being run on your system. If you want to run different variations of code within the same Python kernel, you can highlight the code you want to run and then choose the run option (Alt+Shift+F10 default).

Upvotes: 0

Related Questions