PyDev Interactive Python Shell in Eclipse

17.5k views Asked by At

I've been using Wing IDE for python programming and I am trying to switch to Eclipse, PyDev.

When I run my code in Wing IDE, after finishing the execution the console goes right back to the interactive shell and I can continue on testing, but I don't know how to do this in Eclipse. I'm not sure if I am describing my problem properly so I'll use an example:

Let's say I had a simple source code that looked like this (e.g. test.py):

print("hello")

When I run this in Wing IDE by clicking that green arrow, the console would look like this after execution:

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
[evaluate untitled-1.py]
hello
>>>>

And I can keep doing whatever on the shell and it would know my code (defined functions etc.). But when I do the same thing in Eclipse, the console would simply look like this:

hello

and I have to click "Remove All Terminated Launches" button to go back to the shell.

Can this be done in Eclipse?

2

There are 2 answers

6
Fabio Zadrozny On BEST ANSWER

What you want to use is the interactive console in PyDev (not the regular output when you do a run).

To use it do: Ctrl+Alt+Enter.

Note that if you're in the middle of a debug session, you can also use the debug session console to interact with the program.

It can also be created from the UI in the console view as shown below:

[Create PyDev interactive console [1]

0
Prahalad Deshpande On

From what I know, we can open multiple consoles of a particular type in Eclipse. Whenever we run a script within PyDev, it opens a new console to which it prints the output from the script (including error output). However this is just a new console that is added to the list of already opened consoles. Hence you can switch back to a previously open console by using the Display Selected Console option within the console view ( refer here for a list of all the available console options).

What does this mean?

You can open a new Python interpretor console using the Open Console option within the Eclipse Console view. You can define your methods and play with the interpretor within that console. You now run a Python script that is open within the PyDev editor. A new console gets opened up where-in you see the output from the script (includes error output too). Now if you want to go back to the interactive console, you simply choose the Python Interepretor console that you opened previously from the Display Console option.

Personally, I like this design where-in the output from your script does not mingle and mess up with your experimental sojourns on the Python console. This in turn results in a crisp, clear and concise view of what is happening within the various python environments.

Hope this bit of information helps.