253

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

7 Answers 7

171

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.

3
  • 13
    Thus, you don't need to alter your code, the IPython shell runs your python code just like the normal python shell does Thanks. That is all what I needed to know. Sep 11, 2012 at 13:32
  • Can you give some comments on the execution speed of ipython vs python? I mean pure ipython, not ipython notebook that would involve a browser.
    – Jason
    Jan 7, 2018 at 13:48
  • 2
    @Jason: it's the exact same evaluation loop. There may be some overhead in the presentation layer (parsing for ipython commands, pretty-printing the expression output), but that's all a constant cost. So basically, very, very little difference.
    – Martijn Pieters
    Jan 7, 2018 at 14:50
28

IPython is a powerful interactive Python interpreter that is more interactive compared to IDLE and 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 Jupyter notebook if you used that before.

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

ipython REPL screenshot: showing cell numbers, tab autocompletion

26

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

4
  • Is IPython just the REPL?? Dec 28, 2017 at 16:56
  • @Mr.SuryaaJha It is a REPL, but there is also just the standard python REPL (what you get when you type python in a shell). Apr 25, 2018 at 14:42
  • @BallpointBen then what is the difference between them, or the advantage of IPython?
    – luizfls
    Apr 29, 2021 at 20:48
  • 1
    @luizfls ipython has syntax highlighting, some "magic" like timing functions, and much smarter autocomplete, among other features. I exclusively use it over the standard python REPL. Apr 29, 2021 at 20:49
18

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.

2
  • 1
    Good point, @Roadowl I guess saying "interactive shell" is a bit redundant isn't it.
    – MikeiLL
    Jun 28, 2015 at 3:59
  • @Roadowl: (a year later, but still...) How about any shell running a script in a non-interactive way ? Maybe a simple example: $ sh -c 'foobar=3.14159' ... or maybe I misunderstood yr comment.
    – Cbhihe
    Sep 2, 2016 at 9:27
8

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.

8

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.

2

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.

2
  • 4
    import os; os.system('pwd') is the way I do it in Python. Apr 28, 2016 at 14:28
  • 3
    All % commands are ipython commands and do not work in a regular Python interactive session. That includes %pwd and %ls. The % prefix is optional and only required when there's no conflict with a Python global in your current session.
    – Martijn Pieters
    Nov 22, 2016 at 15:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.