如何将IPython v3笔记本转换为Jupyter v4?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将IPython v3笔记本转换为Jupyter v4?相关的知识,希望对你有一定的参考价值。

有没有办法将我所有的旧v3笔记本批量转换为v4(对于Jupyter)?

我的本地文件系统上有大量旧的v3 IPython笔记本。在将IPython升级到Jupyter之后,每当我打开v3笔记本时,我都会收到一个烦人的提示,通知我文件转换为v4。我对转换完全没问题,但弹出窗口有点烦人。我想通过提前转换我的所有v3笔记本来抢占他们。谢谢!

答案

有一个名为nbconvert的工具可以解决这个问题。

ipython nbconvert --to=notebook testnotebook.ipynb

请始终备份旧文件,因为根据此discussion,转换回来并不总是干净

这是nbconvert工具的全部帮助:

python nbconvert -h
This application is used to convert notebook files (*.ipynb) to various other
formats.

WARNING: THE COMMANDLINE INTERFACE MAY CHANGE IN FUTURE RELEASES.

Options
-------

Arguments that take values are actually convenience aliases to full
Configurables, whose aliases are listed on the help line. For more information
on full configurables, see '--help-all'.

--stdout
    Write notebook output to stdout instead of files.
--quiet
    set log level to logging.CRITICAL (minimize logging output)
--debug
    set log level to logging.DEBUG (maximize logging output)
--inplace
    Run nbconvert in place, overwriting the existing notebook (only
    relevant when converting to notebook format)
--execute
    Execute the notebook prior to export.
--init
    Initialize profile with default config files.  This is equivalent
    to running `ipython profile create <profile>` prior to startup.
--to=<CaselessStrEnum> (NbConvertApp.export_format)
    Default: 'html'
    Choices: ['custom', 'html', 'latex', 'markdown', 'notebook', 'pdf', 'python', 'rst', 'script', 'slides']
    The export format to be used.
--writer=<DottedObjectName> (NbConvertApp.writer_class)
    Default: 'FilesWriter'
    Writer class used to write the  results of the conversion
--output=<Unicode> (NbConvertApp.output_base)
    Default: ''
    overwrite base name use for output files. can only be used when converting
    one notebook at a time.
--profile-dir=<Unicode> (ProfileDir.location)
    Default: ''
    Set the profile location directly. This overrides the logic used by the
    `profile` option.
--ipython-dir=<Unicode> (BaseIPythonApplication.ipython_dir)
    Default: ''
    The name of the IPython directory. This directory is used for logging
    configuration (through profiles), history storage, etc. The default is
    usually $HOME/.ipython. This option can also be specified through the
    environment variable IPYTHONDIR.
--config=<Unicode> (BaseIPythonApplication.extra_config_file)
    Default: ''
    Path to an extra config file to load.
    If specified, load this config file in addition to any other IPython config.
--template=<Unicode> (TemplateExporter.template_file)
    Default: 'default'
    Name of the template file to use
--post=<DottedOrNone> (NbConvertApp.postprocessor_class)
    Default: ''
    PostProcessor class used to write the  results of the conversion
--reveal-prefix=<Unicode> (RevealHelpPreprocessor.url_prefix)
    Default: 'reveal.js'
    The URL prefix for reveal.js. This can be a a relative URL for a local copy
    of reveal.js, or point to a CDN.
    For speaker notes to work, a local reveal.js prefix must be used.
--profile=<Unicode> (BaseIPythonApplication.profile)
    Default: 'default'
    The IPython profile to use.
--log-level=<Enum> (Application.log_level)
    Default: 30
    Choices: (0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL')
    Set the log level by value or name.
--nbformat=<Enum> (NotebookExporter.nbformat_version)
    Default: 4
    Choices: [1, 2, 3, 4]
    The nbformat version to write. Use this to downgrade notebooks.

To see all available configurables, use `--help-all`

Examples
--------

    The simplest way to use nbconvert is

    > ipython nbconvert mynotebook.ipynb

    which will convert mynotebook.ipynb to the default format (probably HTML).

    You can specify the export format with `--to`.
    Options include ['custom', 'html', 'latex', 'markdown', 'notebook', 'pdf', 'python', 'rst', 'script', 'slides']

    > ipython nbconvert --to latex mynotebook.ipynb

    Both HTML and LaTeX support multiple output templates. LaTeX includes
    'base', 'article' and 'report'.  HTML includes 'basic' and 'full'. You
    can specify the flavor of the format used.

    > ipython nbconvert --to html --template basic mynotebook.ipynb

    You can also pipe the output to stdout, rather than a file

    > ipython nbconvert mynotebook.ipynb --stdout

    PDF is generated via latex

    > ipython nbconvert mynotebook.ipynb --to pdf

    You can get (and serve) a Reveal.js-powered slideshow

    > ipython nbconvert myslides.ipynb --to slides --post serve

    Multiple notebooks can be given at the command line in a couple of
    different ways:

    > ipython nbconvert notebook*.ipynb
    > ipython nbconvert notebook1.ipynb notebook2.ipynb

    or you can specify the notebooks list in a config file, containing::

        c.NbConvertApp.notebooks = ["my_notebook.ipynb"]

    > ipython nbconvert --config mycfg.py

以上是关于如何将IPython v3笔记本转换为Jupyter v4?的主要内容,如果未能解决你的问题,请参考以下文章

如何将我的整个输出从iPython笔记本保存为.txt文件?

如何在 ipython 中将 Spark RDD 转换为 pandas 数据帧?

如何在 ipython 中将 Spark RDD 转换为 pandas 数据帧?

IPython复制所有csv文件

IPython插入没有代码的文本

如何将文本文件 (.py) 加载/编辑/运行/保存到 IPython 笔记本单元格中?