Joh11_ · 2022-09-21 09:38
Sorry for the unclear title, my problem arises when using a combination of various Emacs features...
​
I am working remotely on a supercomputing cluster, running Emacs on my machine, and using TRAMP to edit python files on the cluster.
To my great surprise, this works quite well, and the REPL also works flawlessly, as apparently `run-python` (C-c C-p) detects this is a remote file, and use the corresponding interpreter on the remote.
​
However, I realized the version of Python running on the cluster is not the correct one. Indeed, they use the `module` utility to provide multiple conflicting version of programs. This means that I have to run `module load python3` before executing `python3` to make sure I have the latest version.
​
If I SSH into the cluster, this is not a problem, as I just added the module load line in my `.bashrc`. However here, I am not sure how to do it: this is not an interactive shell, so the usual dotfiles are not read (`.bashrc`, `.profile` and friends).
​
Any idea ?
astoff1 · 2022-09-21 15:03
>However here, I am not sure how to do it: this is not an interactive shell, so the usual dotfiles are not read (.bashrc, .profile and friends).
This is indeed one of the issues: Tramp uses a noninteractive shell, so your config needs to be in `~/.profile`.
Also, by default Tramp ignores the PATH set by the remote machine (I never understood why...), so you need some configuration to override this behavior. I use this:
(connection-local-set-profile-variables 'remote-bash
'((explicit-shell-file-name . "/bin/bash")
(tramp-remote-path tramp-own-remote-path "/usr/bin" "/bin")))
(connection-local-set-profiles '(:protocol "ssh") 'remote-bash)
Joh11_ · 2022-09-21 15:25
Thank you so much ! It's working now.
Indeed there was no way I could have figure this out, I did try setting `.profile` before, but as you said it did not set the path.
I just had to modify slightly your snippet, replacing `"/bin/bash"` by the output of `echo $SHELL` on the cluster, and adding the exact Python path to `tramp-remote-path` (`/opt/python/3.9.4.1/bin` in my case).
astoff1 · 2022-09-21 17:27
Out of curiosity, what is \`echo $SHELL\` in your machine?
[deleted] · 2022-09-21 21:48
[deleted]
wargxs · 2022-09-21 21:49
Great answer! What would be the best way to activate a virtual env for this setting? Putting it in profile etc activates it for all connections.
Joh11_ · 2022-09-22 04:35
It's /usr/local/bin/bash ;)