I would like to understand how variable scoping works in Jupyter notebooks.
When I create a bash notebook with two cells, environment variables that are exported are visible across cell boundaries:
In [1]:
export PATH=$PATH:~/samplepath
In [2]:
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/myuser/samplepath
But if I create a Python notebook and use cell magics to achieve the same result, variables do not seem to be visible across cell boundaries any more:
In [1]:
%%script bash
export PATH=$PATH:~/samplepath
In [2]:
%%script bash
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
This behaviour stays the same for different magics (i.e., using an exclamation mark in front of echo instead of the script magic gives the same result).
So, I'd like to understand what the scoping rules are in this case, and how I can make export
truly export variables so that they are visible in the entire notebook.