7

I have written some Jupyter notebooks using original Jupyter notebook web interface. All notebooks are synced nicely in this way.

But now, I would like to edit my notebooks in the VSCode. But I cannot configure syncing notebook file with its python script.

I tried this using jupytext:

  • created file jupytext in the folder ~/.config
  • put the next code into this file:
# Always pair ipynb notebooks to py:percent files
default_jupytext_formats = "ipynb,py:percent"

But no effect!

(Update) Can this be achieved, as a first solution, using VSCode Tasks (I am not used tasks yet)?

May be it possible to run the task with jupytext command if the notebook file is opened/saved/modified?

Andrei Krivoshei
  • 715
  • 7
  • 16
  • How to understand "syncing notebook file with its python script"? Currently VSCode supports exporting [Jupyter](https://code.visualstudio.com/docs/python/jupyter-support#_export-your-jupyter-notebook) as a python file. – Jill Cheng Oct 09 '20 at 07:33
  • Jupytext extension in the Jupyter (web version) automatically synchronize the .py file with the .ipynb. So, I working only with .ipynb file and .py file is synced "itself". In VSCode I can manually export the.ipynb into .py. But how I can config the VSCode or Jupytext to synchronize these files in background, by working with notebook file in the VSCode? – Andrei Krivoshei Oct 09 '20 at 08:48
  • 2
    An extension (still in preview) attempts to do just this: https://marketplace.visualstudio.com/items?itemName=donjayamanne.vscode-jupytext – Hebo Oct 13 '21 at 13:29

2 Answers2

1

Currently, VSCode does not support such a function. The Jupyter function in VSCode is provided by a Python extension, which supports us to convert between .ipynb files and .py files in VSCode.

.ipynb files to .py files : Export as python script.

.py files to .ipynb files : Right click, "Export Current Python File as Jupyter Notebook"

I have submitted the requirement you described, and we look forward to the realization of this feature. Giuhub link: How to synchronize the jupyter file and python file of VSCode.

Jill Cheng
  • 9,179
  • 1
  • 20
  • 25
  • Can this be achieved, *as a first solution*, using Tasks (I am not used tasks yet)? May be it possible to run the task with ```jupytext``` command **if** the notebook file is **opened/saved/modified**? – Andrei Krivoshei Oct 09 '20 at 10:25
  • @Andrei Krivoshei -"jupytext" is an extension of "jupyter" and is currently not supported in VSCode. – Jill Cheng Oct 12 '20 at 06:18
  • 2
    ```jupytext``` can be executed for files syncing from a command line. May be it can be automated using *Task in VSCode* for open notebook file on the save operation (I am not familiar with Tasks)? – Andrei Krivoshei Oct 12 '20 at 09:30
  • @Andrei Krivoshei -For the use of "jupytext" in "Task", we need to do some research, and we will update it here once there is any progress. – Jill Cheng Oct 13 '20 at 01:38
1

I found some issues and really hard to collaborate on Jupytext extensions available, so I have created my own version at: https://marketplace.visualstudio.com/items?itemName=FrancoMilanese.datascientists-utils

It's similar to those mentioned in other answers and comments, but it includes also export to HTML with a TOC, and also a selection of a user defined python interpreter, if you are using python under a virtual env or something like that, please feel free to try it out.

Collaborations are always welcome.

Franco Milanese
  • 402
  • 3
  • 7