Last Site Update: 17 August 2016 | Latest Version: 5.2.0
The interactive console provides a perfect complement to the PyDev environment. It allows interactive editing, running and debugging of your Python project. Some of the highlights are:
Starting the Interactive Console
To use it, do Ctrl+Alt+Enter (while in the PyDev editor) to:
and F2 to:
Alternatively, it can be initialized from the console view from the dropdown for a new console (rightmost corner icon in the console view)
Choosing the Console Type
Choose the console type - this will determine the PYTHONPATH and the interpreter that will be used in the console.
Full Debug Support in Interactive Console
Starting with release 3.0 of PyDev, the interactive console in PyDev can be connected to the full debug infrastructure provided by PyDev. In addition to the new features available since PyDev 2.5.0 of connecting Variables and Expressions view, now breakpoints, single-stepping, etc is all available within the Console.
To enable that feature, go to window > preferences > PyDev > Interactive Console and check 'Connect console to Debug Session?'.
With that setting in place, when a new interactive console is created and the debug perspective is shown, it's possible to see the variables available in the console through the variables view and even add expressions to be resolved in the expressions view. In addition, breakpoints set in code are hit and code can be stepped through.
Running a Python File with a Breakpoint
When a Python file is run (any method, demonstrated here with runfile) any breakpoints will suspend execution.
Running Code with a Breakpoint
If any code is run that has a breakpoint, as for example shown here by having defined a function called "my_sample_function" earlier, code will suspend execution as expected.
Examining Variables with an Active Prompt
When code is being run that is typed by the user in the prompt, the "Interactive Console" thread shows as executing, when the prompt is available, the contents of the namespace of the interactive console is available in the Variables and Expressions view.
User Module Deleter
The user module deleter, a feature activated by using "runfile" to run scripts instead of "execfile", forces all user modules imported modules to be forcefully removed so that a subsequent import of the deleted module is loaded from disk again. Ctrl+Alt+Enter uses runfile and therefore the UMD if it is enabled in the preferences.
To access the UMD preference, go to window > preferences > PyDev > Interactive Console > User Module Deleter (UMD).
The first time runfile is called it collects a list of all the modules already loaded and does not attempt to reload those modules. In addition, built-in modules, C modules and modules listed in the Excluded Modules preference list will not be reloaded.
The UMD achieves the reload by deleting the module from sys.modules so that the subsequent import reloads it fully. It is important to remember that any references to items inside an imported module will not be updated.
Example of User Module Deleter in Action
In step 1 we have a module called myothermodule with a function that returns 1. The program runme.py is being executed showing that myfunc does indeed return 1.
In step 2 we have updated myfunc to return 2, but we have used execfile to execute runme.py. This shows that myfunc has indeed returned 1.
In step 3 we have use runfile to execute runme.py, the UMD shows that myothermodule has been deleted and we can see that myfunc now returns 2.
In this example, at some point prior to running step 1, we did a runfile to preload the list of modules that should not be deleted.
GUI Event Loop Integration
Optionally, when running the interactive console, the interactive console can run the GUI event loop while idle. This allows the launching of interactive GUIs while using the console and is of particular benefit when using matplotlib, mayavi or similar.
The Event loop that is enabled can be selected in window > preferences > PyDev > Interactive Console and selecting the desired item in "Enable GUI event loop integration?".
In addition, the GUI can be set if using IPython with the %gui IPython magic function. e.g. "%gui wx" enables wxPython integration.
For example, with the wxPython event loop on we can do the following with Mayavi. In this example, the console stays fully interactive and while it is idle, the wxPython events are handled, making the Mayavi scene interactive too. (Example function from Mayavi documentation)
When available, IPython is used as the backend for the Interactive Console (as opposed to Python's InteractiveConsole). When in use, all of the wonderful features of IPython are available within PyDev. For example, %edit will open up the file in the fully featured PyDev editor, and %gui provides command line access to GUI Event Loop Integration.
Note: From PyDev 2.2.2 onwards, if IPython is found in the PYTHONPATH, PyDev will use it as the backend for the console. Supported versions are releases 0.10 to 1.1.0, however it is expected that PyDev should work with any newer releases too, please file a bug in the tracker if any issues are encountered.
Always Getting Better
The Interactive Console is one of the areas benefiting from new contributions so in upcoming releases expect many more features and improvements.
PyDev is open source and depends on your contributions! This may be in the form of bug fixes, answers on stackoverflow, new features... Another option is financially supporting it:
And Corporate sponsorship is also available for companies.
Search PyDev-related content
Copyright: Brainwy Software Ltda, 2014-2016