Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jupyter + Remote SSH, ignores .bashrc env vars #163612

Closed
drscotthawley opened this issue Oct 14, 2022 · 1 comment
Closed

Jupyter + Remote SSH, ignores .bashrc env vars #163612

drscotthawley opened this issue Oct 14, 2022 · 1 comment
Assignees

Comments

@drscotthawley
Copy link

Does this issue occur when all extensions are disabled?: Yes/No - N/A: This concerns extensions. Was brought to this Issue page by Pressing "Report issues" link on bottom right of VSCode documentation page "Working with Jupyter Notebooks".

  • VS Code Version: 1.72.2
  • OS Version: Local: MacOS 12.3, Remote: Ubuntu 20.04

Steps to Reproduce:

  1. On remote system, set environment variable -- any environment variable, but I'll do CUDA_VISIBLE_DEVICES -- inside .bashrc:
$ cat ~/.bashrc
...
export CUDA_VISIBLE_DEVICES=7
...
  1. Verify in Remote-SSH Terminal that environment variable is properly set and recognized:
$ echo $CUDA_VISIBLE_DEVICES
7
  1. Run a Juptyer notebook remotely - ie using extensions Remote SSH and Jupyter (installed both locally and on remote system, by choosing Yes whenever prompted. Ensure that Kernel on remote system is properly set when executing notebook).

  2. Observe that your settings are completely ignored: system will execute on GPU 0 instead of GPU 7, and no such environment variable is recognized in the Jupyter notebook execution:

import os 
os.environ['CUDA_VISIBLE_DEVICES']
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In [8], line 2
      1 import os 
----> 2 os.environ['CUDA_VISIBLE_DEVICES']

File /usr/lib/python3.8/os.py:675, in _Environ.__getitem__(self, key)
    672     value = self._data[self.encodekey(key)]
    673 except KeyError:
    674     # raise KeyError with the original key value
--> 675     raise KeyError(key) from None
    676 return self.decodevalue(value)

KeyError: 'CUDA_VISIBLE_DEVICES'

Expected behavior:
That environment variables set in .bashrc, which Remote-SSH extension recognizes, would be preserved when remotely running Jupyter notebooks. (And thus I would be able to control which GPU it executes on, as I do when invoking jupyter locally.)

@drscotthawley
Copy link
Author

Answer: Devs of vscode-jupyter extension think it's "weird" to launch a kernel from a shell (whereas I submit that's the only way the rest of us have ever done it).

Cf. Issue microsoft/vscode-jupyter#8270

Solution: Put environment variables in ~/.env and they will be recognized properly.

....Been using .bashrc for env settings for...30 years?...but ok whatever.

Closing.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants