Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple Python shells in Emacs 'python-mode' with Python or IPython

Is there a way to force a new instance of python-shell while running Emacs? It would be convenient when working on multiple projects with separate working directories (and different sets of modules).

Any attempt to invoke python-shell will only pull up the current instance.

like image 992
hatmatrix Avatar asked Nov 26 '11 21:11

hatmatrix


2 Answers

You need to rename your original python-shell before opening up a new one. Use M-x rename-buffer.

like image 164
Tikhon Jelvis Avatar answered Oct 21 '22 15:10

Tikhon Jelvis


Renaming the buffer doesn't work for me, but you can use the third parameter of run-python.

M - : (run-python nil nil t)RET

Since the binding to switch to the current buffer isn't really helpful you can rebound it to something more useful

(defun my-run-python (&optional new)
  (interactive "P")
  (if new
   (run-python nil nil new)
   (pop-to-buffer (process-buffer (python-proc)) t)))

(define-key python-mode-map (kbd "C-c C-z") 'my-run-python)

And use C-cC-z to switch to the current python interpreter and C-uC-cC-z to switch to a fresh python interpreter.

like image 43
Daimrod Avatar answered Oct 21 '22 16:10

Daimrod