Environment variables PATH and PYTHONPATH not available in notebook

536 views
Skip to first unread message

pobm...@gmail.com

unread,
Mar 5, 2018, 9:38:50 AM3/5/18
to Project Jupyter
Hi,

I set up the vanilla Jupyterhub (0.8.1 on an Ubuntu 16.04 LTS server) with a basically unmodified configuration, except for SSL certs. The bash.bashrc (I also tried /etc/profile) file in /etc/ contains some additional export entries for PATH and PYTHONPATH, but they are never avaiblable in the notebooks unless I set them myself using

import sys
sys
.path.append('/opt/my/speciallibrary')

which as you can imagine is kind of impractical. However, the variables are available in the normal Python REPL as well as in the terminal in Jupyter.

The generated default configuration suggests that those variables are passed through the filter, therefore his shouldn't pose a problem.
which -a suggests all libraries are installed globally and otherwise everything works as it should. I'm running the hub with sudo as this is the suggested method to get multiple users with the default settings. It's a demo server for a notebook plugin prototype and all users can be trusted to not break stuff on purpose.
jupyter troubleshoot displays the correct $PATH and sys.path values, so the variables are in Jupyter but somehow omitted or reset by the kernels?

MinRK figured it could have something to do with the spawners not using login shells so he suggested to run one previous to starting the kernel by setting the configuration

c.LocalProcessSpawner.shell_cmd = ['bash', '-l', '-c']

but unfortunately that doesn't seem to have any effect, either.

Does anyone have an idea what else could have gone wrong or is missing?

I'm comming straight from https://github.com/jupyterhub/jupyterhub/issues/1695 and am hoping to find more input here, because it's still unclear to me if this even is a bug; which it probably isn't.

Best regards.

pobm...@gmail.com

unread,
Mar 8, 2018, 11:20:01 AM3/8/18
to Project Jupyter
If you're having the same issue, you can migitate (if that actually is a bug, that is) by creating a global IPython configuration at /etc/ipython/ipython_config.py or ipython_notebook_config.py and set the paths there like this

 c.InteractiveShellApp.exec_lines = [
     'import sys; sys.path.append("/some/path")'
 ]
 
More information in the github issue.

pobm...@gmail.com

unread,
Mar 8, 2018, 11:20:54 AM3/8/18
to Project Jupyter

*mitigate
Damnit.

Roland Weber

unread,
Mar 9, 2018, 7:15:41 AM3/9/18
to Project Jupyter
Have you tried setting BASH_ENV?


/etc/profile should have worked in combination with --login only.
.bashrc never had a chance, because the shell isn't interactive.

Michael Milligan

unread,
Mar 9, 2018, 12:29:52 PM3/9/18
to jup...@googlegroups.com
I wonder if you just didn't try all the permutations here. You mention that you did try /etc/profile, but possibly you didn't try it again after configuring shell_cmd?

Quoting from the Bash manpage:
       When  bash  is  invoked  as  an interactive login shell, or as a non-interactive shell with the --login
       option, it first reads and executes commands from the file /etc/profile, if that  file  exists.   After
       reading  that  file,  it  looks  for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and
       reads and executes commands from the first one that exists and is readable.  The --noprofile option may
       be used when the shell is started to inhibit this behavior.

Without shell_cmd I wouldn't expect any profile settings to be read, because Popen just directly launches the singleuser server without an intervening Bash process.


--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/8fa8b180-87b3-41ff-b229-f9874b778cd4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


pobm...@gmail.com

unread,
Mar 10, 2018, 12:33:43 PM3/10/18
to Project Jupyter


Am Freitag, 9. März 2018 13:15:41 UTC+1 schrieb Roland Weber:

Nope. Never knew that was an option. Thanks.

/etc/profile should have worked in combination with --login only.
Well, no idea why it didn't. Then again, I'm not a qualified admin.

pobm...@gmail.com

unread,
Mar 10, 2018, 12:39:21 PM3/10/18
to Project Jupyter
To be honest, I didn't bother deleting the lines afterwards; so it probably should have worked.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages