9

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?

5

One way is to use *eshell*.

  • M-x eshell
  • cd /ssh:<server_name>:~
  • run-python /usr/bin/ipython
  • Switch to *Python* buffer.
  • 3
    This is nice, but this doesnot make it possible to send code to the Python buffer. Is that correct? – BakaKuna Jun 10 '16 at 10:56
  • @BakaKuna I solved that check my answer – atevm Feb 20 '18 at 2:15
3

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

  • Good to know that it helped a bit. Thanks – serv-inc Mar 1 '18 at 10:01
0

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.

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.