Vscode-jupyter: Right click on a python file Should be able to export to jupyter (especially if there is more than one cell defined)

Created on 1 Nov 2018  路  10Comments  路  Source: microsoft/vscode-jupyter

All 10 comments

Instead of exporting the output in the _Python interactive_ window (which may contain out of order execution and old outputs), we should be able to generate a .ipynb from the Python source directly. Moreover, it would be nice to have the possibility to automatically generate a *.ipynb (with the same file name) every time we are working with a Python source file that contains cells. In this way the script would be nicely rendered online or on Github.

I second the suggestion by @JackCaster. I would even go one step further and have an option to do this conversion on-the-fly. So something like whenever I save a python file with jupyter markup a corresponding notebook is created. If it already exists, update only the cells that were modified since the last conversion and clear their output

@ronglums, the minimum here is to provide a command. The requests from @JackCaster and @syagev add some other things that sound useful too. What do you think?

We're working on adding a command for directly exporting from py files. @JackCaster @syagev, thanks for the suggestions. I'd like to get a better understanding of your use cases for "conversion on-the-fly". @JackCaster mentioned "In this way the script would be nicely rendered online or on Github." - Let me see if I get this right - if an ipynb is saved along with the py file, then you can view the ipynb files online or on GitHub in the notebook form instead of a py file. Is that what you meant? Curious how else would you use the on-the-fly conversion for?

That's pretty much what I meant. Our use case is that we work directly only on the .py script, but we use notebooks for sharing results. So .py files are kept in version control while .ipynb files are usually excluded, and instead are manually uploaded to some notebook server for quick sharing. So it would be nice if the .ipynb is automagically updated every time .py is updated. But I think this has to be done smart or not done at all (like every automatic thing software does for us). For instance - think of a case where I have the output of a long running task in the .ipynb file and the extension overwrites that without me actually meaning for it to happen...

Do you need the output in the generated ipynb file? Isn't it just generated by whomever views the file?

What I usually would do is to run all cells and then share (so that results are immediately visible to the viewer). The idea of sharing the notebook as a way of sharing resukts is more for ppl to have interactive plots, inspection of variables, an easy way to reproduce, etc.

@JackCaster mentioned "In this way the script would be nicely rendered online or on Github." - Let me see if I get this right - if an ipynb is saved along with the py file, then you can view the ipynb files online or on GitHub in the notebook form instead of a py file. Is that what you meant? Curious how else would you use the on-the-fly conversion for?

Exactly! Please have a look at this example. Note how the .ipynb file is rendered as a notebook directly on Github. The other advantage is that it becomes easier to share our work with people that prefer to work directly with Jupyter notebooks (and we get---finally---the ability to version control our notebooks).

To me, a simple command to export the script as a *.ipynb file would work just fine (for now :) ) as suggested by @rchiodo. I would also suggest to add an option like Run all cells and export to export the code together with the results, but also allow to export only the code (if this includes long running tasks)

Great! Thank you both, I think I have a better understanding now. Let's start with a command to export the py files to .ipynb with an option to "Run all cells and include output in the notebook". The auto-generation on-the-fly work is more complicated - like @syagev said, we need to do it right and not overwrite those long-running cell results for sure! I opened microsoft/vscode-jupyter#1469 to track it separately.

Fixed the export to file in this PR here: microsoft/vscode-python#3548

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ashtou picture ashtou  路  3Comments

dimitry-ishenko picture dimitry-ishenko  路  4Comments

qdlmcfresh picture qdlmcfresh  路  3Comments

allefeld picture allefeld  路  4Comments

chrisjsewell picture chrisjsewell  路  4Comments