So I installed PyDev in Eclipse and started testing it and I have come to an issue.
While using IDLE to run Python I could, for example, create a file, set a variable x = 10 and then make IDLE run said file. I would then be able to ask python for x and it would give me 10. I don't know how to do that in PyDev.
I created a python interactive console and then when prompted chose the "Console for currently active editor" but the console will not recognize x even though the editor has x defined to 10. I did save before creating the console, I also ran the file before I opened the console... I do not know what to do...
Thank you!
Hmmm, I am not familiar with the IDE IDLE, nor do I typically run a file via the console, but maybe I understand your question. The core answer is you need a breakpoint so that execution does not terminate and therefore x=10 is resident in memory. If the breakpoint is set post x=10, then when you reach the breakpoint and execution stops and you type "x" you will get 10.
There is documentation online on the console about how to use it in context of a load of file from with the console. I tend instead to hit shift-F9 while in the file to run it in debug mode. This leaves you in debug console rather than interactive console (you'll see no prompting ">") but you'll still be able to have x=10 when you enter x at break.
Probably misunderstood but though I would give it a shot. Good luck!
After creating the console you have to do an execfile of the python in the console... (ctrl+alt+enter).
See: http://pydev.org/manual_adv_interactive_console.html for details
Note that I believe the current version has an issue with that command -- but I'll probably do a release tomorrow which has a fix for that (PyDev 3.8)
Related
I would like that iPython run automatically when I launch VSC instead of typing ipython and press enter in the terminal. The answer here How to set ipython/jupyter as the default python terminal for vscode? doesn't work as it is for windows but it shouldn't be really different. Also, is there something similar to the 'Execute' button in Spyder instead of typing %run filename ? Thanks !
I presume you mean you want to run the "Python Interactive Window" and not just an iPython console on startup
There is currently no way to run it on startup. At least no way without writing another extension that would run a command when opening a workspace. It would be simple for us to add one though. Probably a workspace setting. Can you log an issue here:
https://github.com/Microsoft/vscode-python/issues/new
For you second question, 'Execute' in spyder, we have 'Run Current File in Python Interactive Window'. This works on any python file. You can get to it through the context menu on a file or through the command palette.
Sadly the nice workflow of spyder is not provided by any official extension at the moment (as far as I know).
But you can implement the basics easily on your own by writing an extension. Even with no experience in TypeScript you can quickly build an extension which starts an IPython console as soon as you open a python file. I also managed to execute a startup script which implements the runfile method. VS Code also allows keybindings for your functions, so that you can almost work like you can with spyder.
Spyder modified the IPython terminal quite a bit though, so it won't feel exactly the same. But after all, everything there is open source so you could implement it yourself, which is what I'm trying to do in my free time.
I would like to know if there is way to figure out (from the IPython console) the .py script that was used to run/execute the python commands interactively and thus got printed into the Ipython console.
For eg.
From the below screenshot, looking at the 3+3 in the Ipython console, I can see that it came in when command from untitled2.py was executed.
However when the scripts get long, and IPython output gets long and you are often shifting scripts on the left side, it can be hard to keep track.
So i was wondering if there is a way i can quickly execute some command or view some setting on Ipython console that can tell me that the above line came from untitled.py.
(Spyder maintainer here) There's no way to know from which Editor you're executing some portion of code, sorry.
However, you could use dedicated consoles (under Preferences > Run > Execute in a dedicated console) to have one console per file you execute, as long as you use F5 to run each one of them.
You could edit each .py script, so the first thing it does is to print its name and functionality.
untitled2.py:
print('untitled2.py')
...
so far I used the Komodo IDE for Python development, but I'm now testing Eclipse with PyDev. Everything works fine, but there is one Komodo feature that I'm missing.
In Komodo I can inspect the running application in a debugger shell. I.e. after hitting a breakpoint I can not only read the content of variables, but I can execute arbitrary Python code (e.g. changing the value of variables) and then continue program execution.
PyDev has also some interactive shell during debugging, but I can only read variables and not change their content. Is this feature not available in PyDev or am I missing something here?
Many thanks,
Axel
As you've seen, you can just use the console directly:
http://pydev.org/manual_adv_debug_console.html
Now, you can also connect the interactive console (which is a bit more advanced) by selecting a stack frame to attach it:
http://pydev.org/manual_adv_interactive_console.html
Yes you can do that. Just type in the console what ever commands you want :). I usually have to right click then
Debug As >> Python run
PyDev is a little bit quirky, but you get used to it.
Please bear with me if this is very basic, as I'm quite new to PyDev. Is there some way to redirect the program output to a PyDev debug console? I'm referring to something like in Matlab. As of now, I have one console for the output where I cannot enter commands, and another in interactive mode. It's not the most convenient thing to keep switching between the two while debugging.
Thanks!
I believe that what you want is the interactive console:
Check http://pydev.org/manual_adv_interactive_console.html
After having it open, you can execute a file and have its tokens available with Ctrl+Alt+Enter (which is also the binding to open it... and you can do a selection and send only some of the contents to it too).
I solved this already, I'm just posting it here because I couldn't figure it out with google, or by reading the docs. I only found it by accident.
To add a breakpoint, right-click on the line that you want to add a breakpoint on and select "Set Breakpoint". The line will become highlighted. (Note that this only works when you are editing a file; it does not work at the interpreter.)
This site has a detailed tutorial about using the IDLE debugger.
On Mac, you need to Control-click instead of right clicking.
Completing the answer supplied by the OP: after setting the breakpoint - you must turn on IDLE Shell's debug mode (using debug --> debugger). When you run the program, press "Go" in the debug window that opens up and IDLE will stop at the breakpoint.
IDLE Shell is the window that appears when you hit F5 to run your Python script.
There is an open Python issue about the lack of documentation for IDLE breakpoints. Contributions welcome!
Update: The on-line documentation and the IDLE help files (for 2.7.4, 3.2.4, and 3.3.0) have been updated, with Nick's help.
You can set breakpoint before it is run.
Set the breakpoint by right clicking on the relevant line of your program
On your python shell, look for Debug - [Debug On] will be shown in your IDLE Python shell
Go back to your program and press F5(hotkey) to run the program, it will stop in the relevant break line(s)
If you want to look at some global variables or line of codes, you can check the box in the debugger
Just adding to this answer (would've commented but for the rules that say I don't have enough reputation to do so): On the Mac you must control-click. The normal "right-click" at least for the trackpad does not work to bring up the contextual menu with the option to set a breakpoint.