21

I started a new project in PyCharm. I have Anaconda 3.6 installed. So, in PyCharm, I selected the Anaconda python.exe as project interpreter.

When I first ran PyCharm, it used the IPython console as "default" console to run my script. Then I restarted my PC and now PyCharm uses the terminal when I run my scripts. Why? I don't want to use the terminal, coming from Anaconda Spyder IDE. I'm used to IPython, I like it and I want to use it.

How can I completely disable the terminal and use only the IPython console?

nbro
  • 15,395
  • 32
  • 113
  • 196
ilpomo
  • 657
  • 2
  • 5
  • 19

2 Answers2

37

Short answer:

  1. Go to File > Default settings > Build, Execution, Deployment > Console and select Use Ipython if available
  2. Go to Run > Edit Configurations and select Show command line afterwards

Tip: Run selected parts of your code with ALT + SHIFT + E


The details:

If you've selected Anaconda as the project interpreter, IPython will most likely be the selected console even though it neither looks nor behaves like the IPython console you are used to in Spyder:

enter image description here

Unlike Spyder, PyCharm has no graphical indicator showing that this is an IPython console.

enter image description here

To make sure it's an IPython console and make it behave more or less like the IPython console you are used to from Spyder, you should follow these two steps:

  1. Go to File > Default Settings > Build, Execution, Deployment > Console and make sure to select Use IPython if available. enter image description here

  2. Go to Run > Edit Configurations and select Show command line afterwards enter image description here

Now you can run selected parts of your code with ALT+SHIFT+E more or less exactly like in Spyder.

If this doesn't do the trick, you should check out these other posts on SO:

Interacting with program after execution

Disable ipython console in pycharm

vestland
  • 55,229
  • 37
  • 187
  • 305
  • 4
    I you are using a virtualenv make sure to install ipython to this virtualenv also since the above setting won't be applied (*Use IPython **if** available*) – Eypros Nov 01 '17 at 15:28
  • Great guide. After using this method I started to see different run-time behavior than I expected. Previously when I executed "Run" on a .py document it would run and complete; the stop button would grey out. However, after selecting **show command line afterwards** the program keeps running, and creates a new instance for the same program. Is there anyway to prevent the PyDev console from restarting on every run and creating a new instance? – Artem Yevtushenko Feb 14 '18 at 03:10
  • 1
    Thanks! I'm not sure actually. By the sound of it, I think you should post that as a new question. For now I can only direct you to a question of my own that may be related to what you are looking for. All the different methods of running and debugging python code is confusing me as well: https://stackoverflow.com/questions/48182309/stepwise-debugging-of-selected-python-code And here: https://stackoverflow.com/questions/48261561/why-does-import-pdb-pdb-set-trace-trigger-two-different-debugging-scenarios-whe These are questions more directly related to Spyder though – vestland Feb 14 '18 at 07:45
  • 3
    ALT + SHIFT + E runs the code in the Python console of Pycharm, but not in the one opened when running a script when you use the option "Show command line afterwards". Is it possible to run pieces of code likewise in that console were your script was run? – rpicatoste Feb 15 '18 at 10:18
  • 1
    @rpicatoste. Not sure, unfortunatey. This would also make for a good question in itself. – vestland Feb 15 '18 at 10:28
  • Also make sure to have IPython installed in your Conda evironment. When PyCharm creates a new environment, this may not be the case. – portux Dec 12 '19 at 12:28
5

In the new version of Pycharm, you have a different option in Edit Configuration.

Go to Run > Edit Configurations and select Run with Python console

enter image description here

bikram
  • 7,127
  • 2
  • 51
  • 63