简体   繁体   中英

"New Console for notebook" for jupyter notebook in visual studio code

Jupyter lab has this feature where I can have a ipython console for every notebook I have opened. Whenever I run a cell inside this notebook, the console will have all the variables defined and modules imported corresponding to notebook. In addition, we can run extra commands and helps in debugging at times. Is there a similar feature in VS code? I really like it and would like to move completely to vs code. Python interactive command line in vscode is the closest to this that I found. However, it is not attached to the notebook and I have to run all the code inside the notebook which is a bit tedious.

I believe this would work: https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Connecting%20with%20the%20Qt%20Console.html

However you're likely looking for a way to do this within VS code. You might be able to do this by runnning %connect_info in a cell, starting a terminal, and then running the appropriate jupyter command.

Something like so: jupyter console --existing kernel-2c0993da-95c7-435a-9140-118c10d33e1a.json

If you're refering to.py files you can do that the same way you would in pycharm. First, you need to put a breakpoint in the code:

incluind a break point

Them you run the code with de debugger: debugger option

then when the code reaches the breakpoint, you will be able to play with the variables, like the jupyter terminal: debugger terminal

I also like to have a JupyterLab-style console open that is connected to a notebook. This is my workaround in order to achieve this in Visual Studio Code (at least it works when my kernel is a remote Jupyter session).

Suppose your notebook is called hello.ipynb .

  1. Create a dummy file called hello.py .
  2. Open hello.py , right-click in the code window and choose Run Current File in Interactive Window . This opens the JupyterLab-style console.
  3. Change the kernel for the interactive window to the same kernel that the notebook hello.ipynb is using.
  4. (Optional) Close the hello.py tab since it is not needed.

Now I have an interactive window sharing everything with the notebook.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM