Configure the shell environment for notebook kernels (~/notebooks/.user_setups)¶
While the terminal in the Notebook Aspect sources ~/.bashrc
, Jupyter Notebook kernels do not.
Instead, you can configure the environment for Jupyter notebooks with the ~/notebooks/.user_setups
file.
With this file, you can set up environment variables and even set up LSST Science Pipelines packages, for your Jupyter notebooks.
Export environment variables for notebooks¶
The ~/notebooks/.user_setups
file is sourced by bash.
This means you can include any valid bash syntax.
For example, you can define environment variables that are accessible from notebooks:
export MYVAR="My env var"
Note
Environment variables exported from ~/.bashrc are not accessible from notebooks.
You need to export those variables from ~/notebooks/.user_setups
instead.
Customizing the EUPS package set up¶
The main use for ~/notebooks/.user_setups
is setting up a package that you’ve locally cloned and built.
See Customizing the EUPS package setup (~/notebooks/.user_setups) for an example.
Updating ~/notebooks/.user_setups for a running notebook kernel¶
If you need to change package setups or environment variables for an already-opened notebook, follow these steps:
Edit and save the
~/notebooks/.user_setups
file.Return to your notebook’s tab and restart the kernel (Kernel → Restart Kernel).
You’ll need to rerun your notebook’s cells after restarting the kernel.
Tip: source ~/notebooks/.user_setups to verify it¶
Since ~/notebooks/.user_setups
is a bash script, it’s sensitive to syntax errors.
You won’t be alerted to syntax errors when you start a new notebook kernel, though.
The best way to check that your ~/notebooks/.user_setups
file is correct is by sourcing it from a terminal:
source ~/notebooks/.user_setups
Note
If ~/notebooks/.user_setups
includes a setup command, ensure that you have set up the LSST environment in the terminal first.