I have integrated PTVS into Visual studio so that i can have intellisense support and debugging capability.
I set Breakpoints at Function definitions, but when i debug the control goes directly out of function. And in some points the Console window pops up and it never iterates to the next line of code.
I liked PTVS but this thing has stuck me up.
In options->Python tools-> Interpreter options i have set it as Python 2.7
Can Anyone tell me whats wrong with the options and why that console screen is appearing.
Thanks in advance.
When you say you're setting breakpoint at function definitions do you mean on the line with the "def ..." or are you setting the breakpoint on the 1st statement of the function?
In Python functions are executable statements so if you're putting the breakpoint on the def line then you're going to hit the breakpoint when the function is being defined rather than being executed.
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 that doesn't help you might want to post the code you're having trouble with or a screenshot of the code with where the breakpoints are set.
Related
I am writing Python scripts in Pycharm with IPython installed. So I can use Python Console in Pycharm to type Python commands and check the immediate output of the codes. However, when I run a script file after pressing 'Run' button (Shift+F10), all the variables and functions are not visible to the Python Console. This is, however, the feature of Spyder, another popular Python IDE. So here is my question: how can I configure Pycharm so that running a Python script file is visible for Python Console? Thanks
You could also run the part of your code you want to test/check in the console by selecting it and then right clicking and clicking on "Execute Selection in Console Alt-Shift-E". That's what I use sometimes when the debugger is not helpful. After running the code (you can also just "run" functions or classes) the console knows the functions and you can use the same features that Spyder has. However, be aware that when you change the code you need to run it in the console once to update the console definitions!
You can not. But you can use pdb (which will break code execution where you need it and you will be able to do the same things, as in the Python Console).
And, which is better and more powerful, you can use PyCharm's debugger. It represents all available variables in tree-like structures and is really handy.
I'm using Visual Studio Code for writing my python application. Inspecting variables and things like setting a watch in the left debugging pane works OK if I write a simple synchronous one-file program.
However, I have code with classes in multiple files, and use various callbacks from other modules. Some which start a new thread.
One of those modules is canopen
I can step thru my code, but when I enter the second line (below)
can0 = canopen.Network()
can0.connect(channel='can0', bustype='socketcan')
then the call stack changes from:
CALL STACK paused on breakpoint
main
<module>
to
CALL STACK paused on breakpoint
MainThread
Thread#15034.........
and simultaneously
the variables pane clears
and the watches in my watch window shows:
can0: not available
How can I (setup VS studio code with Python to) inspect/debug my python code with various threads and code in various files?
Regards,
Bas
New debugger is capable of debugging async applications.
Check out how to set it up
How to update ptvsd used by Visual Studio Code in debug mode
And don't forget to add "subProcess": true, in launch.json
Set the debug to works with Visual Code.
You can see a good article about how you can set the debugger here and here, see:
The setting "stopOnEntry":true will cause the debugger to break at the
first line of the python program being debugged. If this is not
desired, then change the value from true to false. The default value
of this setting is true.
When running the PyCharm debugger and having stopped at a break point, is there a console to run and display some computation with the local variable exposed to me?
What I have in mind is the debugger setup in Matlab, where when stopped at a break point in a function, one can run scripts using the variables inside the function.
If I have understood well what do you mean, yes, PyCharm provides you a console where you can run local scripts or just see the variable's value at breakpoint time.
Start PyCharm debugger and at the bottom of your window you should see the main console.
You have to press a botton named "Show Python Prompt". Now, you should be able to write in console.
Look at the picture for more details.
You can use Evaluate Expression and Watches features to run code while debugging.
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.
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.