-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Notebook cannot load the environment variables automatically #3704
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
Comments
|
The goal of running this command ! was not for adding new environment variables but showing the current environment variables, or to show the issues I met. I know how to add environment variables in Jupyter Notebook. What I am curious is why Jupyter Notebook cannot load environment variables I have already set automatically. Let's say it again for simplicity. Jupyter Notebook cannot launch environment variables automatically after I set environment variables in ~/.bashrc. But those variables can take effect in python. |
Oh, sorry, I misread your issue. Are you launching Jupyter Notebook from a terminal, or from a GUI launcher of some kind?
|
Hi @takluyver Yes, I launch Jupyter Notebook from a terminal. Indeed, I assume the environment variables set in |
Plus, I'm using zsh (to be specific, oh-my-zsh). Although I added environment variables inside |
For me it works: if I add this to my I can also set my own environment variables in |
I have the exact same issue, where did it read the initial variables in its path if it doesn't load from |
Are your environments completely empty or just missing some expected items? If only missing expected items, those items need to be sourced into your runtime environment prior to launching the Notebook server. I suspect that's not the issue per the previous responses. If the environment is (nearly) empty with just a couple items present, then you might be using either of the Gateway projects (Kernel Gateway, Enterprise Gateway). These projects purposely reset the env because the launching server's env is not that of the notebook's user. Another possibility is that your NB application uses its own kernel manager that is controlling its env similar to the gateways, since the only way the server's env is NOT passed along to the kernel process is if |
@sw-gong do you start jupyter notebook by systemd or launchd? If yes then it's non-login shell which is different with your terminal. I meet the same problem when start jupyter by launchd, and fix it by modify the startup script: #!/bin/bash
set -ex
source ~/.bashrc # ADD THIS LINE
$HOME/anaconda3/bin/jupyter notebook --no-browser $HOME/myjupyter |
@guyskk Thank you! I just setup a new compute engine image with jupyter labs as a service with systemd. I kept scratching my head why my python notebooks weren't picking up the right environmental variables I setup in the user's ~/.bashrc file. |
I faced the same problem (using os.environ['VARIABLE_NAME'], changed an environment variable, but the value would'n change in the jupyter notebook). Restarting the kernel or the whole Jupyter didn't help. Had to restart anaconda (from which I had started Jupyter) to get the correct value of the variable. |
I also have the problem, |
still no remedy to this problem? |
Hi @yujund, I don't think there's anything to resolve here, at least that's obvious. I personally cannot reproduce the issue and suspect there's a disconnect somewhere. Perhaps you could share your expectation? Here's what I just did... export ISSUE=3704
jupyter notebook I then start a python kernel and access the environment variable from the cell... Same goes for Whatever environment you have when launching the Notebook server, is the environment you should see from within a launched kernel. There are some variations to this and you'll see differences with the following:
|
@kevin-bates Thanks for your information. It solves the problem. |
Thanks for the update. I'm going to close this as-designed. If others have issues we can talk about re-opening at that time. |
I set my envrionment varibale in ~/.bashrc: export QT_API=pyqt
It shows correctly in the terminal, when I ran export.
However, if I launch Jupyter Notebook, this environment variable is not set by using ! export in side Notebook.
The text was updated successfully, but these errors were encountered: