views:

369

answers:

2

My application has a Python interpreter embedded in it. However there's currently not any way to inspect anything about Python directly. I'd like to be able to pop up an interactive shell at various points to inspect what's going on in Python.

I've found several similar questions which pointed me to code.InteractiveConsole and IPython. However neither of those seem to do anything when I call them - the call appears to complete okay, but nothing visible happens, presumably because my Python instance isn't outputting anywhere I can see.

It was pretty optimistic to think that they'd just magically pop up a new window for me, but it would be nice if I could get that to happen. So, does anybody know if there is an easy way to achieve this (or something similar), or do I have to roll my own dialog and pass the input to Python and display output myself?

Thanks :)

A: 

What have you tried with IPython? Is it the snippets from the documentation:

How about some of the code samples from elsewhere:

I know I fooled around with this a while back and the samples seemed to work, but then I never got a chance to go any further for other reasons.

ars
Not directly from the documentation, but similar; I was attempting to call IPShellEmbed in some fashion.My app is unfortunately in Win32 so I'm not sure how useful the Qt/PyGTK links are (although the approach looks interesting).
Peter
From the IPython Introduction:As of the 0.9 release, IPython requires Python 2.4 or greater. We have not begun to test IPython on Python 2.6 or 3.0, but we expect it will work with some minor changes.IPython is known to work on the following operating systems:LinuxMost other Unix-like OSs (AIX, Solaris, BSD, etc.)Mac OS XWindows (CygWin, XP, Vista, etc.)Qt is usable from a Python installed under WinXP, e.g. Python(x,y), so there doesn't seem to be anything a priori that excludes using this under Win32. YMMV
behindthefall
+1  A: 

I know this isn't what you're asking, but when I've wanted to debug compiled Python (using Py2Exe), I've been very pleased to realize that I can add breakpoints to the exe and it will actually stop there when I start the executable from a console window. Simply add:

import pdb
pdb.set_trace()

where you want your code to stop, and you'll have yourself an interactive debugging session with a compiled executable. Python is awesome that way :)

Greg