I'm trying to activate the debugging functions that are now available on VSCode for Jupyter Notebooks but I'm having some problems with that.
In my interface I can see the button to 'Run by Line' next to every cell but when I click it nothing happens except the normal execution of the entire cell, but that mode is supposed to execute your cell line by line... I've tried putting some breakpoints even I know it is not necessary in that mode but still nothing.
As you can see here the buttons for debugging are shown a few seconds after hitting the 'Run by Line' button but they do nothing.
As a workaround to not being able to use that useful mode, I tried the standard debug mode of VSCode for Jupyter Notebooks which let you go breakpoint to breakpoint on your cell, the problem (I think it is) is that when I use that what VSCode does is open another tab with just the code of the cell I'm debugging in a temporary .py file, which is not the behaviour I would like to have, because I think it should do that on the Notebook tab itself without any new file...
Here I show you a screenshot of the temporary .py that it's created:
That's just the code of my notebook first cell!
Any help with this? I would like to solve both problems or at least one of them.
I've checked the requisites for the debug modes and make sure I fullfill everyone of them but I'm not so used to use the debug functionalities of VSCode so maybe I'm skipping something.
This is a current bug. It was notified to the dev team here:
https://github.com/microsoft/vscode-jupyter/issues/8258
The bug is caused by vscode using a shortened username. In my case GUILLE~1 instead of Guillermo.
The current solution available is to create a new user in your computer with a maximum length of 8 characters.
Related
I am currently writing some Python code in a Jupyter notebook and I wonder if there is any possibility to track the execution of statements directly in Jupyter? I know there is this module called "trace": https://docs.python.org/3/library/trace.html#trace.Trace.results But it seems to me that with "trace" it is only possible to show the flow of execution in the console or to export it to a new file. However, I would like to display it directly in Jupyter Notebooks. Is this possible - with or without the mentioned module - and if yes how?
Thanks for your help.
For something along the lines of debugging code, you may be interested in the cell magic %%debug, discussed here to open a debugger in the notebook and use pdb commands. Or PixieDebugger if you need something fancier.
You may also be interested in the variable inspector extension for JupyterLab. There is (old) an animated example of using it here. You can easily try it out by clicking on launch binder badge there and starting a notebook. Then right-click in the open notebook and select Open Variable Inspector from the list. The animation will show you how to drag the tabs to arrange them side by side on your screen. Now as you run code, you'll see the variables updated.
I am running quite a time consuming python code in PyCharm, where data is initially loaded, then a model is created etc.
I would like to know if it is possible to set a breakpoint at a particular point in the code where the state of the environment will be saved. From there on I want to make edits to the rest of the code, however ideally re-run from the breakpoint I set.
By doing this I would avoid the loading of data, and model training which would be a repeated process.
Is this possible in Python or is there such a functionality in PyCharm?
Thanks
AFAIK and according to this question form 2014, PyCharm does not support hot-swapping code during debug mode. When you set a breakpoint and do some changes in code they will not be applied.
You can however setup a Python propmt in debug console, which will have access to all your variables at the time of current code execution. You can modify their values and check why your code is failing. To do so just click on this icon
yes, you can do check the python code at breakpoints using pycharm debugger
Refer this for how to use it .how to use a debugger in pycharm
You cannot use code modified code in between and then start from that breakpoints using debugger.
little hack to do this, one need to run the python code in debugger mode ie python -i main.py and also need to make sure that there in no interdependence of previous code to the new modified one.
One option I have found is to convert your code to ipython notebook. Put all the heavy-weight/one-time run code in the first few cells and unstable/to be debugged code in the later cells.
Now, you run the first few cells one time, so the output from these cells is stored and readily available always for later cells. Whenever you change code in later cells, you only have to run those cells (unless you modified something in the earlier cells in which case you need to rerun those cells as well).
Pycharm/most python IDEs support running and debugging ipython notebook cells (individually or in groups).
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.
I am trying out IntelliJ. I have installed the Python plugin, and IdeaVim.
I cannot navigate properly across Jupyter Notebook cells using hj. I mean, on normal mode, I cannot go to the next (or previous) cell, even if there is one, using hj.
Is there a way to do it without the mouse, possibly rebindable? I have read the tutorial and tried to find something in the program, but could not.
Ideavim plugin doesn't seem to support Pycharm's notebook implementation as of right now :(
There's an open issue marked as "bug" on Ideavim's issue tracker that was opened back in 2015 and it seems like it doesn't have any progress made since.
However according to the comment in the issue thread you can:
funny way to get into the command mode is type something so that the suggestion panel appears, now press "esc" you will get into Vim command mode
So this might indicate that this could be solved and updated in the future.
As an alternative you can try out jupyter-vim-binding, however it doesn't work with Pycharm either.
I actually know a problem in Spyder. When I Work with matplotlib.pyplot, it automatically shows the figure without any kind of plt.show(). So when I make many different figures, it always shows them all on the same.
I've recently made a program, which is saving one figure by iteration in an for loop, it also opens a figure and at the end, the loop crashes before ending because of too many figures showed.
I would like to know if someone also knows such problems, because I've encountered the in many computers running spyder
You likely are running in iPython with Spyder. iPython automatically runs plt.show(). Press f6 (default), and see if "execute in current python or iPython console" is selected. If so, check the console, the 'tab' should show a blue icon with "iP" and have 'kernal' (or similar) following it.
Simple fix: switch to "execute in dedicated python console" or open a new python console (tab header "python 1")
Source: had same problem.