Search code examples
emacsipythonpython-mode

How to configure emacs to work with ipython


I'm using ubuntu 14.04, emacs 24.3.1, python 2.7.6, ipython 1.2.1, python-mode 6.1.3. Ipython has been working well within emacs for at least a year, however, I have the following problem since two weeks ago.

  1. use C-c! to start default interpreter, ipython shows as I hoped, but instead of split frame and show in another window, it appears in the original code window. (this is a minor problem)
  2. use C-c| to execute a region, python interpreter starts, and the code sends to the python interpreter instead of ipython interpreter

I searched on SO, but this problem seems too recent to have an answer. I googled, found this page https://answers.launchpad.net/python-mode/+question/250905, tried methods therein, still didn't work... Could anyone help me fix the problem? Many thanks!

My .emacs python part looks like

    (require 'python-mode)
    (setq-default py-shell-name "ipython")
    (setq-default py-which-bufname "IPython")
    ; switch to the interpreter after executing code
    (setq py-shell-switch-buffers-on-execute-p t)
    (setq py-switch-buffers-on-execute-p t)
    ; don't split windows
    (setq py-split-windows-on-execute-p nil)

Solution

  • In order to split the window

    (setq py-split-windows-on-execute-p t)

    is needed, resp. reset to default - last line in example. Maybe check settings via M-x customize ... also, which may conflict with setq from init.

    When selecting shell for execution: a shebang in buffer might override default py-shell-name. When shebang should be ignored, use

    (setq py-force-py-shell-name-p t)
    

    See menu

    Python/Customize/Switches/Interpreter

    for an easy way to change this value during current session.