0

I'm using Remote-SSH (Visual Studio Code Remote - SSH) in Visual Studio Code to connect to a server on which I write and run Jupyter notebooks.

I am trying to use a library which requires some environment variables to be set by running source env.profile

I tried putting source env.profile into one of the files in $ZSH_CUSTOM which are sourced on startup by ZSH. With this, the file is correctly sourced in the interactive terminal in the panel.

However it seems that notebooks (and for that matter regular python files) in Visual Studio Code are run inside of a different shell altogether. And that shell doesn't seem to source the same files as ZSH.

After reading this issue I tried adding the source line in various files mentioned there, with no change.

I also tried simply running ! . env.profile inside a cell in the notebook, and it also doesn't work.

Finally I tried using jupyter.runStartupCommands mentioned here but that also didn't work. This makes sense since as far as I know these startup commands are strictly equivalent to running the code inside a cell directly as the very first thing in your notebook

rorshan
  • 166
  • 6
  • Possibly related: https://github.com/microsoft/vscode-jupyter/issues/8270, https://github.com/microsoft/vscode-jupyter/issues/10718. How about just using a `.env` file? [`.env` files are supported by the VS Code Jupyter extension](https://github.com/microsoft/vscode-jupyter/issues/10718#issuecomment-1179206006) Or how about [using the kernel.json file](https://stackoverflow.com/a/53595397/11107541)? – starball Mar 24 '23 at 20:08
  • Thank you for your suggestions. Those were interesting reads. However I found the answer already. Also the issue is that my `env.profile` file also contains some programmatic logic because the value of the variables depend on the state of the server. It wouldn't really be possible to replace that with a static list of environment variables. – rorshan Mar 25 '23 at 09:29

1 Answers1

0

So it turns out that Remote-SSH does in fact source any files that ZSH sources (including those in $ZSH_CUSTOM).

The issue is that the server application for Visual Studio Code Remote-SSH wasn't restarting completely (or maybe there's some caching) when running the "Kill Current VS Code Server" command from a Linux VS Code client. By running killall node on the server I was able to get the dot files to be sourced again.

To add one layer of confusion to it, it seems that if I'm connecting to the same server from Visual Studio Code on a Windows machine, the "Kill Current VS Code Server" does things differently and leads to dot files being sourced.

rorshan
  • 166
  • 6