Run IPython by default and show at startup in Eclipse PyDev - python

As there were no satisfying answers in the following links
Set default directory of Pydev interactive console?
Pydev - startup
pydev console path for the active editor
I'm asking whether there is a way to have IPython as integrated console, opening up at start up and being the console, where the modules are run by default, just like in RStudio.

Well, there's no feature to open it at startup by default, but you can do Ctrl+Alt+Enter to first open it and after it's opened, do Ctrl+Alt+Enter again to execute the current file in that console...
Alternatively, you may also use F2 to send the current line to the console (and jump to the next line, so, it's easy to send a block with multiple F2 keystrokes -- and it should also fix for the indentation required).
See: http://www.pydev.org/manual_adv_interactive_console.html for more details.

Related

Has PyDev an interactive shell (during debugging) as in Komodo?

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.

Setting Breakpoints in IDLE [duplicate]

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.

Execute a default .py file in PyDev

I'm doing a Python project in Eclipse with PyDev. I have a "main" file and some "class" files. I primarily work in the classes, but I need to execute the code via the main file.
At the moment I need to either switch to the main file, or use the drop down menu of the run/debug-button to execute the main file. Pressing the button or using F11, just runs the class file (which is useless)
Is there a way to let PyDev always run a specific file in a project, or perhaps always run the last file executed (which probably will be the best solution).
Thanks in Advance :)
Surely (relaunching the last launch was actually the default in in Eclipse 3.2, never understood why they changed that)...
You can have that back in the preferences at: window > preferences > Run/Debug > Launching and set the Launch Operation to Always launch the previously launched application.
So, Ctrl+F11 will relaunch the last launch and F11 will debug the last launch...
And to launch the file initially you may:
Use a shortcut: F9 to run the current opened file
Go to the menu: Alt + R + S + The number of the Run you wish (It can be Python, Jython, unit-test, etc).
If you are using unit-tests, you could use: Ctrl+F9 to run the unit-tests from the current module (and even selecting which tests should be run).
Relaunch some other launch you did previously: Alt + R + T and choose a previous launch to relaunch.
You may also launch in unit-test mode all files beneath a folder by right clicking the folder > run as > Python unit-test
(reference: http://pydev.org/manual_101_run.html)
And if you use unit-tests, you may also want to take a look at: Continuous unit testing with Pydev (Python and Eclipse)

How do you add breakpoints to a Python program in IDLE?

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.

Python and Eclipse: How to use interactive console after running a module, with the module variables and functions

Let's consider 3 situations:
1) I write a pyhon module in Eclipse (pydev) and run it Ctrl-F11. The module runs and I don't have any control or access (AFAIK) to the module variables and functions.
2) I have defined a python interpreter as an external tool in Eclipse, so I can run it within Eclipse. It works fine, but it does not have tab completion.
3) I open my module with python IDLE (not eclipse) and press f5 (run). It runs on the IDLE opened window and when it finishes I have all the variables and functions form the module to play with.
So I have 2 questions:
a) how to enable, if possible, tab completion in python interpreter in Eclipse? If it's not possible, do I have any alternative to standard Python interpreter?
b) I would like to run step 1) and then be able to continue developing / testing with python interpreter, just like I do with IDLE, but all inside Eclipse. Any suggestion?
Thanks in advance
Not sure how much has changed since the question was asked, but it's now possible to get code completion in the debug console (as of PyDev 1.6.0 according to http://pydev.org/manual_adv_debug_console.html, I'm on PyDev 2.8.1, Eclipse 4.3.0)
Set a breakpoint in the code, on an executable statement (even just print('') or True). Double clicking on the grey vertical bar to the left of the code should do it.
Run in debug mode with F11
Eclipse may prompt to switch to the Debug Perspective; either way, the Console should be visible
You should now be able to click in the Console pane and begin interactive debugging with code completion, even after a traceback. (Ctrl+Space works for me.)
Be aware that multi-line statements won't work unless they're split on : or /:
Update in 1.6.0: commands are evaluated on each new line unless the line starts with ' ' or '/t' or ends with ':' or '/' (so, for entering multi-line statements, the input must be entered properly respecting those limitations).
If you run it as a debug operation in Eclipse, you should be able to set a breakpoint, and you can then examine variables, etc. But you can evaluate random python scripts via the watch functionality.

Categories

Resources