Setting an environment variable in Jupyter

Short one. I wanted to setup an API key env variable in such a way that it’s easily available to Jupyter.

It turns out that the easiest way is by adding it to IPython startup directly.

You can find the path under, ~/.ipython/profile_default/startup/00-startup.py and if it’s not present, create it.

The code that you add in this file is Python and can look in the following format:

import os
os.environ['MY_VAR'] = 'my_value'

After you saved the edited file, don’t forget to restart the kernel.

Cheers