对 Python 开发者而言，IPython 仍然是 Jupyter Notebook 的核心
Jupyter

> 
> Jupyter 项目提供的魔法般的开发体验很大程度上得益于它的 IPython 基因。
> 
> 
> 


![](/data/attachment/album/201907/06/131704z1lsfssamfxrrliq.jpg)


最近刚刚写过我为什么觉得觉得 Jupyter 项目（特别是 JupyterLab）提供了一种 [魔法般的 Python 开发体验](https://opensource.com/article/19/5/jupyterlab-python-developers-magic)。在研究这些不同项目之间的关联的时候，我回顾了一下 Jupyter 最初从 IPython 分支出来的这段历史。正如 Jupyter 项目的 [大拆分™ 声明](https://blog.jupyter.org/the-big-split-9d7b88a031a7) 所说:



> 
> “如果你不明白 Jupyter 是什么，这么说吧，它拥有和 IPython 同样的代码，并且是由同一批人开发的，只不过取了一个新名字、安了一个新家。”
> 
> 
> 


下面这个注脚进一步说明了这一点：



> 
> “我从声明中解读出来的信息是，‘Jupyter 和 IPython 非常相似，但是拥有多种语言’，这也可以很好地解释为什么这个项目的名字已经不再需要包含 Python，因为当时它已经支持多种语言了。”
> 
> 
> 


我明白 Jupyter Notebook 和 IPython 都是从同样的源代码里分支出来的，但是不太清楚 IPython 项目的现状。在大拆分™ 之后它是已经不再被需要了，还是在以另一种方式延续着？


后来我惊讶地发现，IPython 仍然不断在为 Python 使用者提供价值，它正是 Jupyter 体验的核心部分。下面是 Jupyter 常见问题页面的一段截取：



> 
> **有什么语言是需要预装的吗？**
> 
> 
> 是的，安装 Jupyter Notebook 会首先安装 IPython 内核。这样我们就可以在 notebook 上运行 Python 语言了。
> 
> 
> 


现在我明白了，在 JupyterLab（以及 Jupyter Notebook）上编写 Python 程序仍然需要依赖 IPython 内核的持续开发。不仅如此，IPython 还充当了最为强大的默认内核的角色，根据 [这份文档](https://jupyter-client.readthedocs.io/en/latest/kernels.html)，它是其它语言内核之间的枢纽，节省了很多开发时间和精力。


现在唯一的问题是，IPython 本身可以做什么呢？


### IPython 如今的作用


IPython 提供了一个强大的、交互性的 Python shell，以及 Jupyter 的内核。安装完成之后，我可以在任何命令行运行 `ipython` 本身，将它当作一个（比默认 Python shell 好太多的）Python shell 来使用：



```
$ ipython
Python 3.7.3 (default, Mar 27 2019, 09:23:15)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import numpy as np
In [2]: example = np.array([5, 20, 3, 4, 0, 2, 12])
In [3]: average = np.average(example)
In [4]: print(average)
6.571428571428571
```

这就让我们发现了一个更为重要的问题：是 IPython 让 JupyterLab 可以在项目中执行代码，并且支持了一系列被称为 *Magic* 的功能（感谢 Nicholas Reith 在我上一篇文章的评论里提到这点）。


### IPython 让魔法成为现实


JupyterLab 和其它使用 IPython 的前端工具可以让你感觉像是在最喜欢的 IDE 或者是终端模拟器的环境下工作。我非常喜欢 [点文件](https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory#Unix_and_Unix-like_environments) 快捷键功能，Magic 也有类似点文件的特征。比如说，可以试一下 [%bookmark](https://ipython.readthedocs.io/en/stable/interactive/magics.html?highlight=magic#magic-bookmark) 这个命令。我把默认开发文件夹 `~/Develop` 关联到了一个可以在任何时候直接跳转的快捷方式上。


![Screenshot of commands from JupyterLab](/data/attachment/album/201907/06/131754rryf8hnvjv08f832.png "Screenshot of commands from JupyterLab")


`%bookmark`、`%cd`，以及我在前一篇文章里介绍过的 `!` 操作符，都是由 IPython 支持的。正如这篇 [文档](https://ipython.readthedocs.io/en/stable/interactive/magics.html) 所说：



> 
> Jupyter 用户你们好：Magic 功能是 IPython 内核提供的专属功能。一个内核是否支持 Magic 功能是由该内核的开发者针对该内核所决定的。
> 
> 
> 


### 写在最后


作为一个好奇的新手，我之前并不是特别确定 IPython 是否仍然和 Jupyter 生态还有任何联系。现在我对 IPython 的持续开发有了新的认识和，并且意识到它正是 JupyterLab 强大的用户体验的来源。这也是相当有才华的一批贡献者进行最前沿研究的成果，所以如果你在学术论文中使用到了 Jupyter 项目的话别忘了引用他们。为了方便引用，他们还提供了一个 [现成的引文](https://ipython.org/citing.html)。


如果你在考虑参与哪个开源项目的贡献的话，一定不要忘了 IPython 哦。记得看看 [最新发布说明](https://ipython.readthedocs.io/en/stable/whatsnew/index.html)，在这里可以找到 Magic 功能的完整列表。




---


via: <https://opensource.com/article/19/6/ipython-still-heart-jupyterlab>


作者：[Matthew Broberg](https://opensource.com/users/mbbroberg/users/marcobravo) 选题：[lujun9972](https://github.com/lujun9972) 译者：[chen-ni](https://github.com/chen-ni) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
I recently wrote about how I find Jupyter projects, especially JupyterLab, to be a [magical Python development experience](https://opensource.com/article/19/5/jupyterlab-python-developers-magic). In researching how the various projects are related to each other, I recapped how Jupyter began as a fork from IPython. As Project Jupyter's [The Big Split™ announcement](https://blog.jupyter.org/the-big-split-9d7b88a031a7) explained:

"If anyone has been confused by what Jupyter is[1], it's the exact same code that lived in IPython, developed by the same people, just in a new home under a new name."


That [1] links to a footnote that further clarifies:

"I saw 'Jupyter is like IPython, but language agnostic' immediately after the announcement, which is a great illustration of why the project needs to not have Python in the name anymore, since it was already language agnostic at the time."


The fact that Jupyter Notebook and IPython forked from the same source code made sense to me, but I got lost in the current state of the IPython project. Was it no longer needed after The Big Split™ or is it living on in a different way?

I was surprised to learn that IPython's significance continues to add value to Pythonistas, and that it is an essential part of the Jupyter experience. Here's a portion of the Jupyter FAQ:


Are any languages pre-installed?Yes, installing the Jupyter Notebook will also install the IPython kernel. This allows working on notebooks using the Python programming language.



I now understand that writing Python in JupyterLab (and Jupyter Notebook) relies on the continued development of IPython as its kernel. Not only that, IPython is the powerhouse default kernel, and it can act as a communication bus for other language kernels according to [the documentation](https://jupyter-client.readthedocs.io/en/latest/kernels.html), saving a lot of time and development effort.

The question remains, what can I do with just IPython?

## What IPython does today

IPython provides both a powerful, interactive Python shell and a Jupyter kernel. After installing it, I can run **ipython** from any command line on its own and use it as a (much prettier than the default) Python shell:

```
$ ipython
Python 3.7.3 (default, Mar 27 2019, 09:23:15)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import numpy as np
In [2]: example = np.array([5, 20, 3, 4, 0, 2, 12])
In [3]: average = np.average(example)
In [4]: print(average)
6.571428571428571
```


That brings us to the more significant issue: IPython's functionality gives JupyterLab the ability to execute the code in every project, and it also provides support for a whole bunch of functionality that's playfully called *magic* (thank you, Nicholas Reith, for mentioning this in a comment on my previous article).

## Getting magical, thanks to IPython

JupyterLab and other frontends using the IPython kernel can feel like your favorite IDE or terminal emulator environment. I'm a huge fan of how [dotfiles](https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory#Unix_and_Unix-like_environments) give me the power to use shortcuts, and magic has some dotfile-like behavior as well. For example, check out ** %bookmark**. I've mapped my default development folder,

**~/Develop**, to a shortcut I can run at any time and hop right into it.

![Screenshot of commands from JupyterLab Screenshot of commands from JupyterLab](https://opensource.com/sites/default/files/uploads/jupyterlab-commands-ipython.png)

The use of **%bookmark** and **%cd**, alongside the **!** operator (which I introduced in the previous article), are powered by IPython. As the [documentation](https://ipython.readthedocs.io/en/stable/interactive/magics.html) states:

To Jupyter users: Magics are specific to and provided by the IPython kernel. Whether Magics are available on a kernel is a decision that is made by the kernel developer on a per-kernel basis.


## Wrapping up

I, as a curious novice, was not quite sure if IPython remained relevant to the Jupyter ecosystem. I now have a new appreciation for the continuing development of IPython now that I realize it's the source of JupyterLab's powerful user experience. It's also a collection of talented contributors who are part of cutting edge research, so be sure to site them if you use Jupyter projects in your academic papers. They make it easy with this [ready-made citation entry](https://ipython.org/citing.html).

Be sure to keep it in mind when you're thinking about open source projects to contribute to, and check out the [latest release notes](https://ipython.readthedocs.io/en/stable/whatsnew/index.html) for a full list of magical features.

## 1 Comment