I use pdb.runcall to check if a function behaves as I expected. However, it does not have the visual component as IDE debuggers like Pycharm's. Can I do the same thing with Pycharm debugger without running the whole program from the beginning? I want to debug a specific function by using my current environment.
Apparently, we can attach a debugger to the console with a button on the console menu (green bug to the left of the console). If we place a breakpoint in the module or function we want to step into and call the function normally the debugger lands on the breakpoint like the normal debugger. But, with the console debugger, I was able to use the variables in my environment without running the whole application.
Related
I would like to execute arbitrary Python commands in Python console so that they can access current local (and global, any) variables of function during debugging process, like in Matlab debugging.
Is it possible in Python?
UPDATE
I don't have button described by #nanotek
Highlighted button, located in the same place does the opposite thing: it dispays console variables. As you see, console doesn't see found_features variable, which is in currently traced program above.
Yes, this is a common feature of the debugger.
While the debugger is running, click on Console, and then the button Show Python Prompt. You will have access to all the variables available at that state.
Recently some people were complaining about this not working. If you are having issues, try updating to the latest version. I'm on the latest EAP and did not experience this issue.
When I launch my Python program with the debugger in Eclipse with PyDev (Python plug-in for Eclipse), the console is always split into two windows. One where I can actually enter code and the other displays my code entries and their output. See the following snippet.
There is also a "dedicated" debug console which I can start whenever my program is paused, but this requires a manual click (PyDev > Debug Console). This console doesn't have the slip view. See snippet.
Why are there two ways to interact with Python while my program is paused? Why is the default console (from the first screenshot) split into two windows? How can I make my default console be more like the second console without the split view?
The second bottom console keeps a history of user commands that are injected into the current context. It provides a cleaner input mechanism with the ability to navigate through a history of commands. In addition some programs running loops may print to the original console frequently making it difficult to print commands into the top console.
It may have been added for future features as well, like changing the context of the input to a different spot in the code.
That is just my guess. There is a "hide console prompt" terminal button if you do not want to see it. Both consoles can have commands entered in if you are debugging and paused.
My issue with the interactive console is twofold:
When I set a breakpoint in my python code, the execution pauses as expected at the breakpoint and displays all my variables in the "Variables" view. However, the interactive console is not very interactive anymore. I would like to be able to play around with the variables when execution is still paused at the breakpoint.
Ideally I would like to have this same behaviour if I'm not debugging but just working in the interactive console. Is there a way to couple the interactive console to the "Variables" view of the "Debug" perspective. When I open an interactive console now the variables view remains empty.
I am running a fresh install of Eclipse Juno (4.4.0) with PyDev (3.7.0).
I am using the latest pydev and I find the interactive console is still interactive :-) Note that no encouraging prompt is present at the console (e.g. no ">") but if you type one of the variables you see in the variables window you will get a value.. can manipulate etc.
My terminology might be a bit lose. If you mean by interactive console the full ">" console then it is tricky to get that to work during debugging. There is a pydev variable you can set to link it to the debug session but I find it a hassle still.. you have to explicitly switch to such a console.. given a command.. it then throws you back to the normal debug console (which is the one I was referencing as still sensitive to typing variable names etc).. Perhaps I am doing something wrong though for it to be so awkward. I posted on this a few weeks back but there was no reply. I too would like to do debugging in the full console with no hassle. In particular I would like to be able to use its command history to more efficiently manipulate things.
But regardless you can still debug and look at variables just not with the full feature console easily.
Also be aware there seems to be a bug lately (last few releases) where the variables view stays blank. I find that if I close it and reopen it then the variables appear.
Good luck
When I'm developing in Python I often want to debug a specific method, in which case it makes sense to call the method from the interactive console or debug interactive console. However, when a method is called from the interactive windows in PTVS, it doesn't stop at the break points in said method.
If it's possible, please tell me how to do it. If not, I would like to request this feature, and also to know if there is any quicker way to debug a specific method than calling it from the main script.
I'm using PTVS 2.0 RC in Visual Studio 2013 Ultimate
When using the regular (non-debug) Python Interactive window, you can actually attach VS to the python.exe process that it is running by using Debug -> Attach to Process. Once that is done, if the interactive window does something to e.g. hit a breakpoint, the debugger will hit on that breakpoint.
The tricky part is loading the code from a file in such a way that breakpoints are resolved. In particular, $load REPL command will not work because it just reads the file and evals it in the REPL line by line, without preserving the original file context. What you need is to load your script using Python facilities - e.g. import, or open+exec.
There are also some gotchas there - e.g. the REPL window will become unresponsive whenever you are paused on a breakpoint.
I'm debugging my Python code in Eclipse using the Pydev plugin. I'm able to open a Pydev console and it gives me two options: "Console for currently active editor" and "Python console". However none of them is useful to inspect current variable status after a breakpoint.
For example, the code stopped at a breakpoint and I want to inspect an "action" variable using the console. However my variables are not available. How can I do things like "dir(action)", etc? (even if it is not using a console).
This feature is documented here:
http://pydev.org/manual_adv_debug_console.html
The console that opens in the debug perspective is in fact interactive, although it took me a while to realize it. You need to hit return twice after typing something and then it gets evaluated.
More info on the Pydev site here: http://pydev.org/manual_adv_debug_console.html
Double click on "action" or any other variable.
ctrl+shift+D
And if you're using watches, I cant imagine better interaction. You are able to see every change.
When I set a break point and hit F11 Eclipse launches the debugger and prompts to open the "Debug Perspective". You can then open the Window-->Show View --> Expressions which opens the expressions view, you can then right click in the Expressions view windows and choose "Add Watch Expression" to add any expression(such as dir)
Conversely I was also able to type in dir(some expression) in the PyDev console and get the same effect.
I'm using PyDev 1.4.6.2788
On a small monitor, you may not realize that the debug interactive console is different from the regular interactive console: it has a second command prompt at the bottom where you type, not at the top like the normal console.