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.
Related
I just made the transition from Spyder to VScode for my python endeavours. Is there a way to run individual lines of code? That's how I used to do my on-the-spot debugging, but I can't find an option for it in VScode and really don't want to keep setting and removing breakpoints.
Thanks.
If you highlight some code, you can right-click or run the command, Run Selection/Line in Python Terminal.
We are also planning on implementing Ctrl-Enter to do the same thing and looking at Ctr-Enter executing the current line.
You can:
open a terminal at Terminal>New Terminal
Highlight the code you want to run
Hit Terminal>Run Selected Text
As for R you can hit CTRL Enter to execute the highlighted code. For python there's apparently no default shortcut (see below), but I am quite sure you can add yours.
In my ver of VSCode (1.25), shift+enter will run selection. Note that you will want to have your integrated terminal running python.
One way you can do it is through the Integrated Terminal. Here is the guide to open/use it: https://code.visualstudio.com/docs/editor/integrated-terminal
After that, type python3 or python since it is depending on what version you are using. Then, copy and paste the fraction of code you want to run into the terminal. It now has the same functionality as the console in Spyder. Hope this helps.
I'm still trying to figure out how to make vscode do what I need (interactive python plots), but I can offer a more complete answer to the question at hand than what has been given so far:
1- Evaluate current selection in debug terminal is an option that is not enabled by default, so you may want to bind the 'editor.debug.action.selectionToRepl' action to whatever keyboard shortcut you choose (I'm using F9). As of today, there still appears to be no option to evaluate current line while debugging, only current selection.
2- Evaluate current line or selection in python terminal is enabled by default, but I'm on Windows where this isn't doing what I would expect - it evaluates in a new runtime, which does no good if you're trying to debug an existing runtime. So I can't say much about how useful this option is, or even if it is necessary since anytime you'd want to evaluate line-by-line, you'll be in debug mode anyway and sending to debug console as in 1 above. The Windows issue might have something to do with the settings.json entry
"terminal.integrated.inheritEnv": true,
not having an affect in Windows as of yet, per vscode documentation.
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
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.
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.
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.