-
Notifications
You must be signed in to change notification settings - Fork 294
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 notebook doesn't load env variables #8270
Comments
Thanks for the bug. Can you include the output of the 'jupyter' output tab? We should be starting the venv the same way as normal python but something might not be working. |
Having the same issue. |
Having the same issue. |
We don't run your bash rc script before starting a kernel. You'd need to launch VS code from a bash shell and then it should inherit it. |
@rchiodo Even if I export the environment variables through the terminal within VSCode before or while the jupyter notebook is active, I am unable to access them. |
Sorry I'm not following what you're doing here. VS code itself has to be started from a terminal with the environment variables set. Like so:
|
@rchiodo I am ssh into a remote machine with VSCode, not launching from the machine. Then I open the notebook and attempt to access the environment variables. I have tried:
I am having no success with any of those approaches. |
Sorry but that's not supported. Your .bashrc won't be run before we start a kernel. You could workaround this by setting this value to set some environment variables:
Or we could change this issue to an enhancement and add an option to run a kernel from a shell script instead of launching it directly. |
This issue is likely relevant too. It seems weird to me to run a kernel from a shell script, but an |
I agree, that feels weird. Thank you for the redirect. I will take a look. |
I'm not sure if this is the same problem, but for me in a notebook in VS Code In the integrated terminal, with the same virtual environment activated, (Critically, the TeX directory is missing in the notebook. This is not set in .zshrc, but in /etc/profile). When I open a jupyter notebook in the browser from the terminal, I get the correct path, the same as Python in the terminal gives me. I even started VS Code by typing I'm not sure what to do.. I tried restarting everything including my computer, but nothing changed. Update: Apparently this is related to a different issue. This comment helped me solve the problem: #9774 (comment) |
@rchiodo That is the Perfect answer. The content of .bashrc used to be pre-loaded to the Jupyter before, but it stopped working for some reason. Lunching VSCode from a bash terminal fixed the issue for me. Many thanks. |
I find it amazing that something as basic as using from dotenv import load_dotenv
load_dotenv() You need a .env file in the directory you're running this from (or specify the path I think in load_dotenv). The file should have pairs like |
The same issue was reproduced again, and the solution is in this comment |
Does this issue occur when all extensions are disabled?: Can't check because i only have a remote ssh access to the concerned computer.
Version: 1.62.1
Commit: f4af3cbf5a99787542e2a30fe1fd37cd644cc31f
Date: 2021-11-05T10:56:50.217Z
Electron: 13.5.2
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.4.0-89-generic snap (Ubuntu 18.04.5 LTS)
I'm not sure how to reproduce this issue since it mysteriously stopped working overnight. Anyway, here what happens:
so that in a python file, os.getenv('SOME_VARIABLE') works just fine.
However inside a jupyter notebook (with the good kernel), this variable is set to None. If it can help, the PYTHONPATH is:
/path/to/my/home/.vscode-server/extensions/ms-toolsai.jupyter-2021.10.1101450599/pythonFiles:/path/to/my/home/.vscode-server/extensions/ms-toolsai.jupyter-2021.10.1101450599/pythonFiles/lib/python
I tried setting:
in the json settings file but it didn't change anything.
I guess this is a jupyter bug since it works in a python file.
The text was updated successfully, but these errors were encountered: