6

I'd like to run two instances of IPython in Emacs at the same time, one with Python 2, and the other Python 3: is it something doable or there's something in the way python.el is designed that would prevent it?

1 Answer 1

5

Yes, that's possible. Add the following code to your init-file (note that you might have to adapt /usr/bin/ipython2 and /usr/bin/ipython to point to appropriate executables for IPython 2 and IPython 3, respectively):

(defun run-python2 ()
  (interactive)
  "Run IPython with Python 2."
  (let ((python-shell-buffer-name "Python 2"))
    (run-python "/usr/bin/ipython2 -i" nil t)))

(defun run-python3 ()
  "Run IPython with Python 3."
  (interactive)
  (let ((python-shell-buffer-name "Python 3"))
    (run-python "/usr/bin/ipython -i" nil t)))

(global-set-key (kbd "C-c C-2") 'run-python2)
(global-set-key (kbd "C-c C-3") 'run-python3)

With this in place you can launch IPython 2 via C-c C-2 and IPython 3 via C-c C-3. (You can of course change these bindings to your liking.)

5
  • Thanks a lot, it works very well, and will be very useful to me. Commented Mar 13, 2015 at 17:21
  • Minor detail: would you happen to also know if it's possible to have different prompt colors for each REPL? Commented Mar 13, 2015 at 17:25
  • @cjauvin You're welcome :) As for your follow-up question: I'm pretty sure it's possible to have different prompt colors for each REPL. However, ANSI colors are not my area of expertise... I suggest you ask a separate question about changing prompt colors ("How to change prompt color in Python REPL?"). If someone can outline a general approach, I can certainly help you integrate the solution into run-python2 and run-python3. Commented Mar 14, 2015 at 20:12
  • Thanks! I found a simple solution: simply adding if sys.version_info[0] < 3: c.PromptManager.in_template = r'{color.Green}In [\#{color.Green}]: ' in my ~/.ipython/profile_default/ipython_config.py. Commented Mar 15, 2015 at 16:04
  • @cjauvin That's great -- a non-Emacs solution, but hey, if it gets the job done... ;) Commented Mar 15, 2015 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.