11

I am trying to run an ipython interpreter remotely (with Emacs 24.5 and native python.el), but I'm not sure I have the right approach: whenever I try to run such a command for instance (which gets triggered with C-c C-c):

Run Python: /ssh:<server_name>:/usr/local/bin/ipython -i

(with <server_name> a valid entry in my ~/.ssh/config, and ipython available at that remote location), I get an error like:

Warning (emacs): Python shell prompts cannot be detected.
If your emacs session hangs when starting python shells
recover with `keyboard-quit' and then try fixing the
interactive flag for your interpreter by adjusting the
`python-shell-interpreter-interactive-arg' or add regexps
matching shell prompts in the directory-local friendly vars:
  + `python-shell-prompt-regexp'
  + `python-shell-prompt-block-regexp'
  + `python-shell-prompt-output-regexp'
Or alternatively in:
  + `python-shell-prompt-input-regexps'
  + `python-shell-prompt-output-regexps'

as well as:

env: /ssh:<server_name>:/usr/local/bin/ipython: No such file or directory

in a *Python* buffer.. Is this making use of tramp, and is python.el able to run remote interpreters in such a way?

cjauvin
  • 594
  • 4
  • 15

3 Answers3

7

One way is to use *eshell*.

  • M-x eshell
  • cd /ssh:<server_name>:~
  • run-python /usr/bin/ipython
  • Switch to *Python* buffer.
PythonNut
  • 10,243
  • 2
  • 29
  • 75
6

@serv-inc answear is the best approach here:

(setq python-shell-interpreter "ssh yourhost ipython" python-shell-interpreter-args "--simple-prompt -i")

but it will still fail with the error:

No such file or directory, ssh\

You must reference an executable on your path, so direct shell commands do not play, but writing a wrapper script will solve that, let's name it remote-python:

#!/usr/bin/env bash
ssh hostname -t "ipython $@"

-t will force pseudo terminal allocation.

$@ will delegate all the received arguments to the remote ipython.

This script must be in a directory which is defined in your PATH variable. You can check this inside Emacs with:

(getenv "PATH")

then you can set remot-python as your interpreter:

(setq python-shell-interpreter "remote-python"
            python-shell-interpreter-args "-i --simple-prompt")

If you get a warning about redline support:

(setq python-shell-completion-native-enable nil)

Note:

The beauty of this method, that it should work with almost every interpreter. I also tested it with julia-mode's REPL and You can write an interactive function to switch your remote/local interpreters.

atevm
  • 928
  • 7
  • 16
-1

Try evaluating (or even in .emacs)

(setq python-shell-interpreter "ssh yourhost ipython"
      python-shell-interpreter-args "--simple-prompt -i")

and use like your local eval on any python file.

The first line sets the remote ipython as your default interpreter. The second line fixes an ipython problem.

orluke
  • 103
  • 2
serv-inc
  • 816
  • 6
  • 26