debug script with pydev in eclipse - python

I have used standart ide for python - IDLE for a long time. It has convinient debug. I can write script, press F5 and it is possible to use all objects in terminal.
Now i want working with eclipse and pydev plugin. Is there any similar way to debug in eclipse?

Yes, there is.
Just start debugging - as far as I know, you have to set breakpoint, otherwise program just run to the end. And when stopped at breakpoint, in console window, click open console icon -> choose pydev console -> PyDev Debug Console.
Let me know if it works for you.

The PyDev debugger should be better to work with breakpoints and in a context... See: http://pydev.org/manual_101_run.html for basic instructions.
Note that when in a breakpoint you can simply issue commands in the console to print variables, etc.
Now, just for completeness, what IDLE has is closer to the PyDev interactive console: http://pydev.org/manual_adv_interactive_console.html Mostly, press Ctrl+Alt+Enter in your file and it'll execute the file in a buffer for you to work interactively.

Related

PyDev: Running code to interactive console

As my problem is quite simple I'll try to make this question simple aswell. The problem I'm having concerns the PyDev interactive console. I can bring up the console just fine without problems, and even use it as an interactive shell, just as I would be able to with IDLE. However, when I try to run my code that I've written in my project module, it won't run to the interactive console, but to the Eclipse default console. The default console displays the program just fine, but since it's not an interactive shell, I can't do anything afterwards.
With that being said, my question is: How do I get my code to run to the PyDev interactive console, and not the Eclipse default one? Thanks in advance!
For making the symbols of the current editor available in the interactive console, use Ctrl+Alt+Enter (which will do a runfile in the interactive console context).
Also, make sure you read: http://www.pydev.org/manual_adv_interactive_console.html
First it is possible. Second, off top of my head it might be you need to change in preferences where the debug perspective points to? Look through pydev preferences too. Sorry not to be more helpful. Away from computer.
Run the program from the code window. Try hitting F9 whike cyrsor in your code window. Results and bugs should show up in console.

Debugging inside PyCharm IPython

Is it possible to hit graphical breakpoints when running codes in PyCharm's IPython console?
i.e.:
You have a script foo() in foo.py
You place a graphical breakpoint inside foo() from the editor (the red dot next to line number)
You import foo into a PyCharm's IPython console and execute foo() (Note: not running from a debug configuration!)
As suggested by #bvanlew in comments, PyCharm (both community and professional edition) now supports attaching debugger onto interactive console. Click the debug button as shown below, and PyCharm's debugger will kick in when the breakpoint is hit.
Yes, it is. But it is not automatic.
(Using 4.5.2, Windows 8)
I run an IPython Notebook, and let PyCharm kick off the notebook backend.
I hit Tools, Attach to Process and attempt to identify the PID of the notebook process. I'm yet to find a smooth way of doing this. Currently I use Process Explorer, find the pycharm entry, and watch for the new sub-processes after the notebook server starts. You want the leaf python.exe process, e.g:
6268 pycharm.exe
1235 python.exe (new when notebook launched)
7435 conhost.exe (new)
9237 python.exe (new - pick this PID)
I can now run a cell and hit the graphical breakpoints.
Enjoy.
On ubuntu i had to change the line kernel.yama.ptrace_scope = 1 in /etc/sysctl.d/10-ptrace.conf to kernel.yama.ptrace_scope = 0
otherwise pycharm was not able to attach to the ipython process.

Debug with internal command window Python Tools and Vistual Studio 2013

I just installed Python Tools with Visual Studio 2013 (Shell) and whenever I run a debug of the program, a separate window pops up for the interpreter:
I can however run the program using the internal interactive console:
However this doesn't seem to stop at any breakpoints that I set in the code. Is there a way to force the system to use the internal console for debugging instead of using a separate windowed console?
You can hide the shell by changing Environment options in Python Tools with Visual Studio, change the default path to point pythonw.exe.
Here is the steps:
TOOLS -> Python tools -> Python Environment
Open Environment options, Add Environment, Enter whatever you want to name it.
Copy all the options in the default Environment except change "Path:" to path of pythonw.exe. Hit OK and made the new Environment as the default environment.
There's no way to hide the console window entirely, but all output from it should be tee'd to Output window, so you can use that if you don't like the console.
There's also a Debug Interactive window (Debug -> Windows -> Python Debug Interactive) that you may find of help, if what you want specifically is being able to stop at breakpoints and then work with variables etc in a REPL environment. Once enabled, this window will provide you a live REPL of the debugged process, and when you're stopped anywhere, you can interact with it. Like Output window, it does not suppress the regular console window, but it mirrors its output.
Although this seems old, solution pasted elsewhere can help someone searching an answer.
I cannot comment since I don't have rep.
Here is the solution: https://stackoverflow.com/a/22486749/4809808
As far as the console window it will generally open unless you mark your app as a Windows application in project properties (this will launch pythonw.exe which doesn't include a console window).
If you right click on your project and choose Properties in the "General" tab there's a "Windows Application" checkbox below Working Directory.

python interactive console in debugger is not "interactive"

I am running Pydev 2.7.3 with Eclipse 1.5. I'm trying to use the interactive console with the debugger (i.e. what I would like to do is insert a breakpoint in a file, run the file up to that breakpoint, then muck around with stuff in the interactive debugger). It seems like what I am trying to do fits this exactly: http://pydev.org/manual_adv_debug_console.html
But the interactive console does not DO anything. It prints "pydev debugger: starting", and any prints from before the breakpoint in my file, but when I try to type commands and execute them it is not responsive. It just advances one line and does nothing when I hit enter.
What's the deal? Or how can I start looking under the hood to figure out what is going on here?
EDIT
To be clear, I'm looking for the kind of functionality described here:
Jump into a Python Interactive Session mid-program?
Interactive console using Pydev in Eclipse?
but the "interactive" console that appears (as indicated in the answers to those questions) is not interactive.
EDIT: Problem seems to have resolved. No explanation other than restarting.

Interactive console using Pydev in Eclipse?

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.

Categories