jupytext

MIT License
Python
跨平台
2021-12-02
首席测试

CI Documentation Status codecov.io Language grade: Python Code style: black GitHub language count Conda Version Pypi pyversions Binder:notebook Binder:lab

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

Use cases

Common use cases for Jupytext are:

  • Doing version control on Jupyter Notebooks
  • Editing, merging or refactoring notebooks in your favorite text editor
  • Applying Q&A checks on notebooks.

Install

You can install Jupytext with

  • pip install jupytext
  • or 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

    With a click on the text file in Jupyter Notebook

    (click on the image above to try this on Binder)

    With a right click and open with notebook in Jupyter Lab

    (click on the image above to try this on Binder)

Paired 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

    the "pair notebook with..." commands in Jupyter Lab

    the "pair notebook with..." menu entries in Jupyter Notebook

    jupytext at the command line

    with e.g.

    jupytext --set-formats ipynb,py:percent notebook.ipynb
    

    see the documentation.

    or a local or global 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.

Which text format?

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:

  • Use the percent format, a format with explicit cell delimiters (# %%), supported by many IDE (Spyder, Hydrogen, VS Code, PyCharm and PTVS)
  • Or use the light format, if you prefer to see fewer cell markers.

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

More resources?

If you're new to Jupytext, you may want to start with the FAQ or with the Tutorials, or with this short introduction to Jupytext: .

加载中

暂无资讯

暂无问答

Jupytext 将 Jupyter 和 PyCharm 完美融合了

作者:Marc Wouts 来源:机器之心 Jupyter Notebook 真的是让人又爱又失望,在有的场景下它极其便利,但是在很多大模型或复杂项目上,它又无能为力。在 Jupytext 这个项目中,作者希望既能利...

2021/01/08 08:00
14
0
太棒了!Jupyter 与PyCharm 完美融合,Jupytext 来啦!

点击上方“AI算法与图像处理”,选择加"星标"或“置顶” 重磅干货,第一时间送达 项目作者:Marc Wouts 转自:机器之心 Jupyter Notebook 真的是让人又爱又失望,在有的场景下它极其便利,但...

2021/01/07 17:00
54
0
太棒了!Jupyter 与PyCharm 完美融合,Jupytext 来啦!

项目作者:Marc Wouts 转自:机器之心 Jupyter Notebook 真的是让人又爱又失望,在有的场景下它极其便利,但是在很多大模型或复杂项目上,它又无能为力。在 Jupytext 这个项目中,作者希望既...

2021/01/15 14:32
11
0
送书|Jupyter Notebook的三大短板,都被这个新工具补齐了

Jupyter 已经家喻户晓,它把笔记、代码、图表、注释融合在一个交互式的笔记本里,还能添加各种扩展功能。可谓机器学习入门进阶研究之神器。 可是,神器也有短板: 文件是固定的JSON格式,体积...

2020/12/18 08:22
9
0
Pycharm ipynb

jupyter notebook 试试: pip install jupytext 如果运行,需要jupyter package,只查看代码不需要这个包 pip install jupyter_contrib_nbextensions...

2020/06/27 17:08
123
0
熬了半宿!梳理了 JupyterLab 上 20 个超级实用的插件!

JupyterLab 是 Jupyter 的旗舰项目,是数据科学中最受欢迎、最具影响力的开源项目之一。Jupyter 生态系统的一大成功是,如果你缺少一些东西,则有一个开源扩展,或者你也可以自己创建它。 在...

2021/01/06 12:02
215
0
GitHub趋势榜第一!如何用30天吃掉TensorFlow2.0?

天下苦tensorflow久矣!😭 尽管tensorflow2.0宣称已经为改善用户体验做出了巨大的改进,really easy to use,但大家学得并不轻松。 tensorflow2.0官方文档和tensorflow1.0官方文档显然是出...

2020/04/05 11:30
10
0
GitHub超4K星!如何用30天吃掉TensorFlow2.0?

天下苦tensorflow久矣!😭 尽管tensorflow2.0宣称已经为改善用户体验做出了巨大的改进,really easy to use,但大家学得并不轻松。 tensorflow2.0官方文档和tensorflow1.0官方文档显然是出...

2020/05/23 18:08
49
0

没有更多内容

加载失败,请刷新页面

返回顶部
顶部