可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
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.
回答2:
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 is basically the "recommended" Python shell, which provides extra features. There is no language called IPython.
回答4:
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:
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:
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.
回答7:
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.