Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 289
MorningGlory Avatar asked Aug 13 '18 21:08

MorningGlory


People also ask

How do I stop Pycharm console?

Stop a programon the toolbar, or press Ctrl+F2 .

Why is Pycharm running in console?

The main reason for using the Python console within PyCharm is to benefit from the main IDE features, such as code completion, code analysis, and quick fixes.

How do I stop the Python console from running?

To stop code execution in Python you first need to import the sys object. After this you can then call the exit() method to stop the program running.


3 Answers

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

like image 152
Pavel Karateev Avatar answered Oct 22 '22 11:10

Pavel Karateev


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

like image 25
exan Avatar answered Oct 22 '22 13:10

exan


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.

like image 20
Siddhant Tanpure Avatar answered Oct 22 '22 11:10

Siddhant Tanpure