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