visual-studio-codevscode-extensions

How do I open a .py file in the notebook editor of VSCode


VSCode has a notebook editor that works for .ipynb files. Is it possible to open a regular .py file (optionally annotated with the "percent" syntax) in the integrated notebook editor? If yes, how?

Right clicking the file in the editor or the file explorer gives no option of opening with the notebook editor. Also running the "Open in Notebook Editor" and "Open in Preview Notebook Editor" commands from the Command Palette doesn't seem to do anything.

Only reference I could find is the following, however that refers to .ipynb only: https://code.visualstudio.com/docs/python/jupyter-support#_create-or-open-a-jupyter-notebook


Solution

  • I'm a developer on this extension. The notebook editor is just for opening up Notebook (.ipynb) files. .py files will open up in the normal VSCode editor. However if you have code cell (#%%) annotations in your .py file you should have both CodeLenses and command palette commands that you can use to run blocks of code in jupyter. The output from those blocks will show up in an interactive window that is similar to the notebook editor.