notebook: Crash when running jupyter notebook with a user with id != 1000

Apparently, jupyter notebook command attempts to write something on folder /run/user/1000 which belongs to user with id 1000. If jupyter notebook is run with a different user, the following stacktrace appears:

Traceback (most recent call last):
  File "/opt/jupyter/bin/jupyter-notebook", line 11, in <module>
    sys.exit(main())
  File "/opt/jupyter/local/lib/python2.7/site-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/opt/jupyter/local/lib/python2.7/site-packages/traitlets/config/application.py", line 595, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/opt/jupyter/local/lib/python2.7/site-packages/traitlets/config/application.py", line 74, in catch_config_error
    return method(app, *args, **kwargs)
  File "/opt/jupyter/local/lib/python2.7/site-packages/notebook/notebookapp.py", line 1021, in initialize
    self.init_configurables()
  File "/opt/jupyter/local/lib/python2.7/site-packages/notebook/notebookapp.py", line 815, in init_configurables
    connection_dir=self.runtime_dir,
  File "/opt/jupyter/local/lib/python2.7/site-packages/traitlets/traitlets.py", line 529, in __get__
    return self.get(obj, cls)
  File "/opt/jupyter/local/lib/python2.7/site-packages/traitlets/traitlets.py", line 508, in get
    value = self._validate(obj, dynamic_default())
  File "/opt/jupyter/local/lib/python2.7/site-packages/jupyter_core/application.py", line 99, in _runtime_dir_default
    ensure_dir_exists(rd, mode=0o700)
  File "/opt/jupyter/local/lib/python2.7/site-packages/ipython_genutils/path.py", line 167, in ensure_dir_exists
    os.makedirs(path, mode=mode)
  File "/opt/jupyter/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/run/user/1000/jupyter'

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 16 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I had the same problem. export XDG_RUNTIME_DIR="" eliminated the problem.

You can also (at least in bash) unset XDG_RUNTIME_DIR for the same effect.

This is coming from the environment variable $XDG_RUNTIME_DIR. Normally, when you log in, that is set to a newly created directory which only your user has access to. I’m guessing that it doesn’t get set again when you use sudo to change user.

I think we have a fallback if it’s not set, so the easiest thing might be to unset the environment variable after sudo-ing. In fact, I thought sudo dropped environment variables by default. 😕

Actually, I found out something still more interesting: The id which jupyter uses to decide which folder it should write in (this /run/user/{id}), seems to be the id of the user which the session was initially open with.

So, if I ssh into a host using a user which has id X and then I sudo su - anotheruser, when I run jupyter from user anotheruser the folder it uses is /run/user/X

unset XDG_RUNTIME_DIR type above in your terminal and you are good to go.

Export XDG_RUNTIME_DIR worked for me!.

I followed the remote jupyter tutorial from AlexanderLabWHOI (https://alexanderlabwhoi.github.io/post/2019-03-08_jpn-slurm/)

I run jupyter in a Surm cluster. I wrote there a function in ~/.bash_profile to call Jupyter with the specified port:

function jpt(){ mkdir run export XDG_RUNTIME_DIR=/home/my_username/run/ jupyter notebook --no-browser --port=$1 } In my local machine I have another function in my ~/.bashrc file:

function jptnode(){ ssh -t -t my_username@hpc.address.edu -L 8888:localhost:8888 ssh node1 -L 8888:localhost:8888 }