question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document how to set environment variables for user notebooks

See original GitHub issue

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:

  • setting it in .bashrc
  • setting it in .profile
  • setting it in the SystemD configuration file
  • adding a new configuration file in the directory /opt/tljh/config/jupyterhub_config.d
  • setting it via kernel parameters (see this StackOverflow answer)
  • setting it in the spawner configuration
  • setting it via sudo tljh-config set user_environment.MY_ENVIRONMENT_VARIABLE my_value
  • adding the environment variable name to the list of forwarded environment variables

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!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:14

github_iconTop GitHub Comments

17reactions
yuvipandacommented, May 19, 2019

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.

6reactions
ksbekcommented, Nov 25, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set env variable in Jupyter notebook - Stack Overflow
To set an env variable in a jupyter notebook, just use a % magic commands, either %env or %set_env , e.g., %env MY_VAR=MY_VALUE...
Read more >
Adding environment variables to notebooks that you own - IBM
Click Add a variable, specify the environment variable name and value, and click Save. For a list of supported built-in Jupyter notebook environment...
Read more >
How to Set and List Environmental Variable in Python and ...
Step 1: Set Environmental Variable with Jupyter Magic. Simplest option to set environment variables in Jupyter Notebook and JupyterLab is to use magic...
Read more >
Setting and Using Environment Variables in Jupyter Notebooks
Use the built-in %env magic command or pass the printenv or set commands to the operating system. Why is Jupyter Notebook not seeing...
Read more >
Customizing User Environment
The user environment is the set of software packages, environment variables, and various files that are present when the user logs into JupyterHub....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found