Python和IPython有什么区别?

问题:Python和IPython有什么区别?

Python和IPython之间到底有什么区别?

如果我用Python编写代码,它是否可以按原样在IPython中运行还是需要进行修改?

我知道IPython应该是Python的交互式外壳,但仅此而已?还是有一种叫做IPython的语言?如果我在IPython下编写某些内容,它将在Python中运行,反之亦然吗?如果存在差异,我怎么知道它们是什么?Python使用的所有软件包都可以像在IPython中那样工作吗?

What exactly is the difference between Python and IPython?

If I write code in Python, will it run in IPython as is or does it need to be modified?

I know IPython is supposed to be an interactive shell for Python, but is that all? Or is there a language called IPython? If I write something under IPython, will it run in Python, and vice-versa? If there are differences, how do I know what they are? Will all packages used by Python work as is in IPython?


回答 0

ipython 是使用python构建的交互式shell。

从项目网站:

IPython提供了丰富的工具包,可帮助您充分利用Python,并具有以下功能:

  • 强大的Python Shell(基于终端和Qt)。
  • 基于Web的笔记本,具有相同的核心功能,但支持代码,文本,数学表达式,内联图和其他富媒体。
  • 支持交互式数据可视化和GUI工具箱的使用。
  • 灵活,可嵌入的解释器,可加载到您自己的项目中。
  • 易于使用的高性能并行计算工具。

请注意,前两行告诉您它可以帮助您充分利用Python。因此,您不需要更改代码,IPython shell就像常规python shell一样运行python代码,只具有更多功能。

我建议阅读IPython教程,以了解使用IPython时获得的功能。

ipython is an interactive shell built with python.

From the project website:

IPython provides a rich toolkit to help you make the most out of using Python, with:

  • Powerful Python shells (terminal and Qt-based).
  • A web-based notebook with the same core features but support for code, text, mathematical expressions, inline plots and other rich media.
  • Support for interactive data visualization and use of GUI toolkits.
  • Flexible, embeddable interpreters to load into your own projects.
  • Easy to use, high performance tools for parallel computing.

Note that the first 2 lines tell you it helps you make the most of using Python. Thus, you don’t need to alter your code, the IPython shell runs your python code just like the normal python shell does, only with more features.

I recommend reading the IPython tutorial to get a sense of what features you gain when using IPython.


回答 1

IPython基本上是“推荐”的Python shell,它提供了额外的功能。没有称为IPython的语言。

IPython is basically the “recommended” Python shell, which provides extra features. There is no language called IPython.


回答 2

即使在查看了该线程之后,我仍然认为ipython是python shell的同义词,换句话说,在命令行中键入python会将其置于ipython模式。

实际上,如上所述,它实际上是一个非常酷的交互式外壳程序(命令行程序),可以从iPython.org安装或通过运行

pip install ipython

或更广泛的内容:

pip install ipython[notebook]

从命令行。

Even after viewing this thread, I had thought that ipython was a synonym for the python shell, in other words that typing python at the command line put one into ipython mode.

It is in fact, as referenced above, a very cool interactive shell (command line program) that can be installed from iPython.org or simply by running

pip install ipython

or the more extensive:

pip install ipython[notebook]

from the command line.


回答 3

IPython是功能强大的交互式Python解释器,与标准解释器相比,它更具交互性。

要获取标准的Python解释器,请键入,python然后会>>>从您可以工作的地方获得提示。

要获取IPython解释器,您需要先安装它。pip install ipython。您键入ipython并得到In [1]:提示,然后In [2]:输入下一条命令。您可以调用history以检查以前的命令列表,并写回%recall 1以调用该命令。

即使您在Python中,也可以直接运行shell命令,例如!ping www.google.com。如果您之前使用过的话,它看起来就像是命令行的Jupiter笔记本。

您可以使用[Tab]自动完成,如图所示。

IPython is a powerful interactive Python interpreter that is more interactive comparing to the standard interpreter.

To get the standard Python interpreter you type python and you will get the >>> prompt from where you can work.

To get IPython interpreter, you need to install it first. pip install ipython. You type ipython and you get In [1]: as a prompt and you get In [2]: for the next command. You can call history to check the list of previous commands, and write %recall 1 to recall the command.

Even you are in Python you can run shell commands directly like !ping www.google.com. Looks like a command line Jupiter notebook if you used that before.

You can use [Tab] to autocomplete as shown in the image.


回答 4

Python和IPython之间几乎没有区别,但是它们仅是对少量语法的解释,就像@Ryan Chase提到的语法一样,但是即使在Ipython中,Python的内在本质也得以保留。

IPython的最好部分是IPython笔记本。您可以将所有工作放入脚本,图像文件等笔记本中。但是使用基本Python,您只能将脚本制作在文件中并执行。

开始时,您需要了解IPython是为了在单个集成容器中支持富媒体和Python脚本而开发的。

There are few differences between Python and IPython but they are only the interpretation of few syntax like the few mentioned by @Ryan Chase but deep inside the true flavor of Python is maintained even in the Ipython.

The best part of the IPython is the IPython notebook. You can put all your work into a notebook like script, image files, etc. But with base Python, you can only make the script in a file and execute it.

At start, you need to understand that the IPython is developed with the intention of supporting rich media and Python script in a single integrated container.


回答 5

与Python相比,IPython(由Fernando Perez在2001年创建)可以完成python可以做的所有事情。Ipython甚至提供了额外的功能,例如制表符完成,测试,调试,系统调用和许多其他功能。您可以将IPython视为Python语言的强大接口。

您可以使用pip 安装Ipython-pip install ipython

您可以通过在终端窗口中键入来运行Ipythonipython

Compared to Python, IPython (created by Fernando Perez in 2001) can do every thing what python can do. Ipython provides even extra features like tab-completion, testing, debugging, system calls and many other features. You can think IPython as a powerful interface to the Python language.

You can install Ipython using pip – pip install ipython

You can run Ipython by typing ipython in your terminal window.


回答 6

根据我的经验,我发现某些在IPython中运行的命令不在基本Python中运行。例如,pwdls不要单独在基地的Python工作。但是,如果以%诸如:%pwd和开头,则它们将起作用%ls

另外,在IPython中,您可以运行cd命令,如下所示: cd C:\Users\ …即使在前缀为a的%情况下,这在基本python中似乎也不起作用。

From my experience I’ve found that some commands which run in IPython do not run in base Python. For example, pwd and ls don’t work alone in base Python. However they will work if prefaced with a % such as: %pwd and %ls.

Also, in IPython, you can run the cd command like: cd C:\Users\… This doesn’t seem to work in base python, even when prefaced with a % however.