| Reference | Downloads | Github

IPython embedded shell

I was wondering if it is possible to create an embedded IPython terminal to allow for interactive debugging of my psychopy application. For example, you can type self.states to view the current values of the state variables, and when you manipulate their values, you can interactively inspect and manipulate the PsycoPy stimuli while the system is running.

Hi @nicklczk, you could always use the pdb module, which “defines an interactive source code debugger for Python programs”. To use this, you will need to run your Python script from the command line, and ensure that your PsychoPy window is not running in full screen, otherwise you will not be able to see your console. From your Python script, import the pdb module at the top of your script (or follow example below). Find the location where you wish to add a breakpoint to your script, and add:

import pdb

When your script reaches the breakpoint, the command console will become interactive. You can evaluate variables, create and manipulate PsychoPy objects whilst the debugger is running. E.g., from the console I can create a new rect, and draw it on screen using:

myRect = visual.Rect(win, size=.5)
win.flip()  # remember to call winflip, otherwise your changes will not appear on screen.
1 Like