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:
jupytext in the folder ~/.config# 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?
There have been some exciting recent developments for syncing Python .py script (in py:percent format) and Jupyter notebooks (.ipynb) in VS Code. A new extension, Jupytext Sync (GitHub) by Victor Negîrneac, now provides the requested features and is designed to work similarly to JupyterLab's Jupytext integration, but directly in VS Code.
You can easily install the extension from the marketplace: Jupytext Sync (marketplace).
According to these GitHub discussions, the extension is even endorsed by the JupyText project itself. This is great news for anyone looking for seamless integration and automatic synchronization between Jupyter notebooks and text files in VS Code.
One can create a Visual Studio Code hotkey to quickly synchronize the .py script (in py:percent format) and the .ipynb Jupyter Notebook on demand with JupyText as described in this article:
jupytext e.g. with pip install jupytext.task.json file (see below) in the .vscode/ folder of your workspace. This defines a default VSCode task that runs the jupytext command to synchronize the two files..py or .ipynb files, type the shortcut Ctrl+Shift+B to synchronize their content.The file task.json should contain
{
"tasks": [
{
"label": "JupyText Sync",
"type": "shell",
"command": "jupytext --sync ${file}",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "never",
}
}
]
}
This is not fully automatic, but nearly as convenient.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With