Closed agentS closed 5 years ago
Apologies for the delayed response, and thank you for opening this issue.
You can put standard JupyterHub config directives under /opt/tljh/config/jupyterhub_config.d/<some-config-file-name>
. So you may create a file at /opt/tljh/config/jupyterhub_config.d/environment.py
and add the following contents:
c.Spawner.environment = {
'TEST': 'blah'
}
This should put the environment variables in your users' notebook servers.
Wow, thank you so much for pointing out how to set env variables. I've lost hours over it, too.
For the record and for future reference: sagemath (called "sage" in conda) requires two environment variables. Putting the following in /opt/tljh/config/jupyterhub_config.d/environment.py makes sage stop complaining:
c.Spawner.environment = {
'SAGE_ROOT': '/opt/tljh/user',
'SAGE_LOCAL': '/opt/tljh/user'
}
Well, sage is still not working, due to some very troublesome prompt_toolkit related breakage that I'm trying to figure out, but at least I'm that one step closer. (It's somewhat frustrating.)
Dear @yuvipanda, this solution does not work for me. As mentioned above, I've created the /opt/tljh/config/jupyterhub_config.d/environment.py
file and added only this content:
c.Spawner.environment = {
'TEST'_VAR: 2,
}
However, after logging in with one of the TLJH users, I do not see the TEST_VAR
using os.environ
. Is there anything I am missing? Do I have to restart TLJH? Do I need to recreate delete and recreate the user? Is the c.Spawner.environment
command not correct?
Thank you.
Hello @filippo82!
You should restart TLJH after adding it - the config is only read on startup. After that, you need to stop & start the user server again. Try that out and see if that works?
Hi @yuvipanda, thanks! Yes,
tljh-config reload
tljh-config reload proxy
did the trick!
Since I have your attention ... :) I would also need to source a file to set some variables, like this one to set up the Intel compiler:
source $HOME/longpath/psxevars.sh intel64
Is there a way to do that within TLJH?
Thank you.
@filippo82 unfortunately there isn't a clean way to do that - source
is from bash, while this all is in Python. You might be able to write some python code that parses it (or even executes it!) and pass those on.
Also you probably don't need the reload proxy
OK, thanks!
Apologies for the delayed response, and thank you for opening this issue.
You can put standard JupyterHub config directives under
/opt/tljh/config/jupyterhub_config.d/<some-config-file-name>
. So you may create a file at/opt/tljh/config/jupyterhub_config.d/environment.py
and add the following contents:c.Spawner.environment = { 'TEST': 'blah' }
This should put the environment variables in your users' notebook servers.
@yuvipanda I want to set env vars per user. How can I do that? Thanks in advance.
Is this also the way to update the PATH variable ? I would like to add a new path in the PATH variable without overriding, how can I do this using this method ? (Or there is another way to do so)?
Related to https://github.com/google/evcxr/issues/140
Is this also the way to update the PATH variable ? I would like to add a new path in the PATH variable without overriding, how can I do this using this method ? (Or there is another way to do so)?
Related to google/evcxr#140
I tend to add multi-user PATH variables via c.Spawner.environment
as well as /etc/environment
(ubuntu 18.04) to make sure it shows up in kernels and terminals (disclaimer: I'm only working with python kernels)
This issue has been mentioned on Jupyter Community Forum. There might be relevant details there:
I managed to modify PATH as below configuration in values.yaml
hub:
extraConfig: |
def notebook_dir_hook(spawner):
spawner.environment = {'PATH': '/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/shared'}
This issue has been mentioned on Jupyter Community Forum. There might be relevant details there:
sorry for this comment because the issue is already closed, but really I need your help for my issue:
https://github.com/jupyterhub/the-littlest-jupyterhub/issues/805 @yuvipanda please help Thanks a lot for your understanding
I'm having an issue where I update the /opt/tljh/config/jupyterhub_config.d/environment.py
file but the environment variables are not updating. I have executed sudo tljh-config reload
and sudo tljh-config reload proxy
, logged out and back in with my user, and shut down and restarted the notebook kernels, but the new environment config present in environment.py
is not accessible to a call to os.environ
in the notebooks. What could cause this?
edit: The only thing that would work to refresh the environment variables was to restart the instance (we're running on AWS EC2).
So I really wanted environmental variables on a per user instead of global (/opt/tljh/config/jupyterhub_config.d/environment.py) level. The way that I found to do it per user is in a file /home/jupyter-
import os
os.environ["VAR1"] = "FOO"
os.environ["VAR2"] = "BAR"
Hopefully this will help someone else-- after making a change to the config, I kept reloading the tljh config, as well as the user's kernel, but the change would not take affect. Turns out you need to restart the user's Jupyter "server". As in:
Edit: To clarify, seems like the minimal required steps after updating the /opt/tljh/config/jupyterhub_config.d/environment.py
are:
tljh-config reload
Hi,
First of all, thank you for your great work on this project! It really is a pleasure to work with it.
I am trying to set an environment variable, so I can access it using
%env MY_ENVIRONMENT_VARIABLE
within Jupyter notebooks. Despite trying for several hours, I have not been able to achieve this simple task.I tried the following approaches:
.bashrc
.profile
/opt/tljh/config/jupyterhub_config.d
sudo tljh-config set user_environment.MY_ENVIRONMENT_VARIABLE my_value
I would be most grateful if somebody could tell me the correct way to set an environment variable on the Linux system so that I could use it within my notebooks. Thank you!