I declared several variables in my bash (through ~/.bash_profile) , and they work in bash itself as well as in python started in bash.
Example:
export PUIBy="Dropbox/CUSP/1_1_PUI/PUI_Bycicle_Research/"
However, when I start Jupyter notebook, os.environ
dont see any of them, showing some default list of variables (PWD, SUDO_USER, USERNAME, JPY_PARENT_PID, SSH_AUTH_SOCK, SUDO_UID, GIT_PAGER etc)
My sistem is Mac OS El Captain, anaconda ipython 2.7
Actually this question has nothing to do with Jupyter. It is more related to how different .bash files are loaded.
To quote from here
.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.
Because you put your variables into .bash_profile it is only available in terminal shells but not in non-interactive shell.
Jupyter-notebook is a web application, even though it runs on your local machine and you access it from local machine (in most cases). Each time you open a notebook it launches a kernel in its own non-interactive shell. So if you want environment variables to be visible from the shell, put them into .bashrc
file, not .bash_profile
Also, to view which variables are set, use !export
command in your Jupyter notebook
Try env
instead of export
eg:
env PUIBy="Dropbox/CUSP/1_1_PUI/PUI_Bycicle_Research/" jupyter notebook
Source: link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With