Have you always wished Jupyter notebooks were plain text documents? Wished you could edit them in your favorite IDE? And get clear and meaningful diffs when doing version control? Then... Jupytext may well be the tool you're looking for!
Jupytext is a plugin for Jupyter that can save Jupyter notebooks as either
Common use cases for Jupytext are:
You can install Jupytext with
pip install jupytext
conda install jupytext -c conda-forge
.Please note that Jupytext includes an extension for Jupyter Lab. In the latest version of Jupytext, this extension is compatible with Jupyter Lab >= 3.0 only. If you use Jupyter Lab 2.x, please either stay with Jupytext 1.8.2, or install, on top of the latest pip or conda version of Jupytext, a version of the extension that is compatible with Jupyter Lab 2.x:
jupyter labextension install jupyterlab-jupytext@1.2.2 # For Jupyter Lab 2.x
Then, restart your Jupyter server (for more installation details, see the install section in the documentation).
When Jupytext is installed, .py
and .md
files have a notebook icon. And you can really open and run these files as notebooks
The most convenient way to use Jupytext is probably through paired notebooks.
To pair a given .ipynb
or text notebook to an additional notebook format, use either
jupytext
at the command linewith e.g.
jupytext --set-formats ipynb,py:percent notebook.ipynb
see the documentation.
jupytext.toml
configuration file.with e.g. the following content:
formats = "ipynb,py:percent"
see the documentation.
When you save a paired notebook in Jupyter, both the .ipynb
file and the text version are updated on disk.
When a paired notebook is opened or reloaded in Jupyter, the input cells are loaded from the text file, and combined with the output cells from the .ipynb
file.
You can edit the text representation of the notebook in your favorite editor, and get the changes back in Jupyter by simply reloading the notebook (Ctrl+R in Jupyter Notebook, "reload notebook" in Jupyter Lab). And the changes are propagated to the .ipynb
file when you save the notebook.
Alternatively, you can synchronise the two representations by running jupytext --sync notebook.ipynb
at the command line.
Jupytext implements many text formats for Jupyter Notebooks. If your notebook is mostly made of code, you will probably prefer to save it as a script:
# %%
), supported by many IDE (Spyder, Hydrogen, VS Code, PyCharm and PTVS)If your notebook contains more text than code, if you are writing a documentation or a book, you probably want to save your notebook as a Markdown document
.md
file (without its outputs) on GitHubIf you're new to Jupytext, you may want to start with the FAQ or with the Tutorials, or with this short introduction to Jupytext: .
首先记录一些问题: base环境中安装了jupytext,其他新建的虚拟环境就不用安装jupytext,就可以正常查看运行.md文件 出现问题,比如拿不定是哪种命令格式时,去官网查 在pycharm等IDE中运行出现错误,按照网上的解决方法尝试还是不能解决的,去cmd或者shell中运行看报错是否还是一样的错误。比如一开始我这里的错误是Fatal Python error: Py_Initiali
折腾了一下jupytext,是一个jupyter的插件,可以进行多种格式之间的转换尤其是ipynb到md之间,废话少说,上手安装。 首先安装插件: notebook里安装: pip3 install jupytext --upgrade jupyterlab里安装: jupyter labextension install jupyterlab-jupytext --minimize=False
1.Jupyter的安装教程:https://jupyter.org/install.html 2.Jupyter的安装教程2:https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html 3.Jupytext安装使用教程:https://www.pianshen.com/article/85341701