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?

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.)

  • Thanks a lot, it works very well, and will be very useful to me. – cjauvin Mar 13 '15 at 17:21
  • Minor detail: would you happen to also know if it's possible to have different prompt colors for each REPL? – cjauvin Mar 13 '15 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. – itsjeyd Mar 14 '15 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. – cjauvin Mar 15 '15 at 16:04
  • @cjauvin That's great -- a non-Emacs solution, but hey, if it gets the job done... ;) – itsjeyd Mar 15 '15 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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