How to open IPython interpreter in emacs?

24,006

Solution 1

I don't know what Prelude is, but if you can install the latest Emacs (i.e, Emacs with Fabian's python-mode included), then you can use the following to let Python mode know your preferred choice of interpreter. Then you just need to call M-x run-python:

--

(when (executable-find "ipython")
  (setq python-shell-interpreter "ipython"))

--

Solution 2

UPD Detailed instructions for beginners:

  1. Copy this:

    (defun ipython ()
        (interactive)
        (term "/usr/bin/ipython"))
    
  2. Try first launching Emacs as emacs -q from the terminal. -q means don't load any customized code. It means that in this mode your emacs will behave exactly like mine.

  3. You should now be at the welcome screen. Press q.
  4. You should now be in the *scratch* buffer. Press C-y to paste the code you copied from the browser.
  5. Position your cursor at the very end of the code, right after the last parenthesis.
  6. Press C-j to evaluate the code. The name ipython pops up.
  7. Now you can execute this command as any other e.g. M-x ipython.
  8. If you want this change to become permanent, append the code to your ~/.emacs.

Solution 3

Seems a bit late, however was also having similar problem, wanted to have ipython as default python interpreter for my emacs 24.x. The following worked like a magic -

(require 'python)
(setq python-shell-interpreter "ipython")
(setq python-shell-interpreter-args "--pylab")

thanks to http://www.flannaghan.com/2013/08/29/ipython-emacs for saving my day and hopefully yours.

PS: seems having anaconda preinstalled in your system helps...

Solution 4

I've tried abo-abo's approach to running ipython inside of emacs. Its a pretty slick way of shortcutting shell functions within emacs. However, you do lose emacs functionality when you are in the shell (e.g. can't M-x o out of the shell)

Instead, I personally think that using the Emacs builtin shell command (M-x shell) is much better. You can run ipython within the Emacs builtin shell and still have all Emacs functionality that we all know and love.

Share:
24,006

Related videos on Youtube

Eric Wilson
Author by

Eric Wilson

Software developer, experienced in Java and Python in Linux environments, formerly a professor of mathematics. I'm a father of five children, and a husband of one wife.

Updated on March 01, 2020

Comments

  • Eric Wilson
    Eric Wilson over 4 years

    In order to use IPython during Python development in Emacs, I have been opening up a terminal, and typing ipython. This doesn't seem like the right way to do it.

    For one thing, my buffer lists this buffer as *ansi-term*, which is confusing, as I often end up with multiple terminals, one of which is dedicated to Python. I also see that I can open a python interpreter directly with M-x python-shell. It seems like there ought to be a similar option for IPython.

    Is there a better way to use the IPython interpreter in Emacs?

    I'm using Emacs 24 with Prelude.

    • mike
      mike almost 10 years
      I am thinking that the reference to Prelude (which I think is a bunch of pre-defined emacs settings in github) doesn't really help here. Also, I'm reluctant to put this as an Answer, but have you seen EIN (Emacs IPython Notebook: github.com/tkf/emacs-ipython-notebook ) ? This is probably what you're after.
    • BBSysDyn
      BBSysDyn almost 6 years
      I recommend emacs-ipython - github.com/burakbayramli/emacs-ipython
  • Eric Wilson
    Eric Wilson almost 11 years
    I'm not particularly experienced with Emacs. Would you mind being more explicit about what it means to "Try this"?
  • mike
    mike almost 10 years
    I love this answer, because it illustrates how get Emacs to actually understand the session (where the prompts are, use emacs python mode instead of simple cominf) and use ipython's own completion.
  • mike
    mike almost 10 years
    This answer is okay, far as it goes, but it isn't really much better than the asker's own solution, just a bit faster to start. Actual integration between Emacs inferior python mode and IPython would be the Right Way. See kindahero's answer
  • rambalachandran
    rambalachandran over 9 years
    I added this code to my .emacs and it works as expected. However if I try to use ipython notebook through ein (M-x ein:notebooklist-open) it throws me an error that says Wrong type argument: stringp, nil. Anyways to integrate this with ein?
  • kindahero
    kindahero over 9 years
    @WanderingMind with out a backtrace I can't tell you what's wrong. May be ask a new question on emacs.SE with backtrace details.
  • salotz
    salotz about 7 years
    For me this screws up the formatting of the ipython shell. In emacs 24 at least.
  • gboffi
    gboffi almost 3 years
    if you know that the conditional is not necessary, i.e., 1st thing you do on any new computer is to install IPython, you can just use customize, more specifically M-x customize-apropos <RET> python-shell <RET>. Of course you will start customizing python-shell-interpreter (to ipython) but next you have over 25 other possibilities for customizing in detail your Emacs-IPython experience.