I’m using emacs23 with tramp to modify python scripts on a remote host.
I found that when I start the python shell within emacs it starts up
python on the remote host.
My problem is that when I then try to call python-send-buffer via C-c C-c it comes up with the error
Traceback (most recent call last):
File “”, line 1, in ?
ImportError: No module named emacsTraceback (most recent call last):
File “”, line 1, in ?
NameError: name ’emacs’ is not defined
Now, I must admit that I don’t really know what’s going on here. Is there a way for me to configure emacs so that I can evaluate the buffer on the remote host?
Many thanks.
Edit: I’ve followed eichin’s advice and re-implemented python-send-region. See my answer below.
Short answer: not without writing some missing elisp code.
Long version: In
python.el,run-pythonaddsdata-directory(which on my Ubuntu 10.10 box is/usr/share/emacs/23.1/etc/) to$PYTHONPATH, specifically so that it can findemacs.py(as supplied by the local emacs distribution.) Then it does a(python-send-string "import emacs")and expects it to work…It looks like the
defadvicewrappers thattrampuses don’t actually passPYTHONPATH, so this doesn’t work even if you have the matching emacs version on the remote system.If you
M-x customize-variable RET tramp-remote-process-environment RETthen hit one of the
INSbuttons and addPYTHONPATH=/usr/share/emacs/23.1/etcthen hitSTATEand set it to “current session” (just to test it, or “save for future sessions” if it works for you) it almost works – the complaint goes away, in any case, because the remote python can now find the remoteemacs.py. If you now go back to the original question, doingpython-send-buffer, you just run into a different error:No such file or directory: '/tmp/py24574XdA'becausepython-modejust stuffs the content into a temporary file and tells the python subprocess to load that.You’d have to change
python-send-region(the other functions call it) and particularly the way it usesmake-temp-fileto be tramp-aware – there’s even atramp-make-tramp-temp-fileyou could probably build upon. (Be sure to post it if you do…)