Jupyter Notebook: Access to the file was denied
Asked Answered
A

5

23

I'm trying to run a Jupyter notebook on Ubuntu 21.10. I've installed python, jupyter notebook, and all the various prerequisites. I added export PATH=$PATH:~/.local/bin to my bashrc so that the command jupyter notebook would be operational from the terminal.

When I call jupyter notebook from the terminal, I get the following error message from my browser:

Access to the file was denied.

The file at /home/username/.local/share/jupyter/runtime/nbserver-260094-open.html is not readable.

    It may have been removed, moved, or file permissions may be preventing access.

I'm using the latest version of FireFox.

I've read a number of guides on this and it seems to be a permissions error, but none of the guides that I've used have resolved the issue. Using sudo does not help, in fact it causes Exception: Jupyter command "jupyter-notebook" not found. to be thrown.

That being said, I am still able to access the notebook server. If I go to the terminal and instead click on the localhost:8888 or IP address of the notebook server then it takes me to the notebook and everything runs without issue.

I would like to solve this so that when I run jupyter notebook I'm taken to the server and don't need to go back to the terminal window and click the IP address. It's inconvenient and can slow me down if I'm running multiple notebooks at once.

Any help on this issue would be greatly appreciated!

Anthropometry answered 18/1, 2022 at 10:10 Comment(0)
L
42

I had the same problem.

Ubuntu 20.04.3 LTS Chromium Version 96.0.4664.110

This was the solution in my case:

Create the configuration file with this command:

jupyter notebook --generate-config

Edit the configuration file ~/.jupyter/jupyter_notebook_config.py and set:

c.NotebookApp.use_redirect_file = False

Make sure that this configuration parameter starts at the beginning of the line. If you leave one space at the beginning of the line, you will get the message that access to the file was denied.

Otherwise you can clean and reinstall JupyterLab

jupyter lab clean --all
pip3 install jupyterlab --force-reinstall
Longo answered 18/1, 2022 at 10:19 Comment(5)
Generating and editing the config file as you suggested worked perfectly! Thank you!Anthropometry
also, make sure that c.NotebookApp.use_redirect_file = False is uncommented (remove the # at the start of the line, if there is any)Capitation
I can't edit configuration file: Permission denied.Helbon
did you generate the config file first ? i also specified in my answer that you shouldn't have a space at the beginning of the line otherwise you will get that denied access. If you can go through this you can try to make a clean reinstall.Longo
It works with jupter-lab also, with minor changes: jupyter-lab --generate-config, and change c.ServerApp.use_redirect_file = FalseFrady
V
12

If anyone is curious, the reason for the problem is that the file:// URI scheme cannot access files in hidden directories directly under the home directory (~/.local in your case).

You can recreate the problem with: mkdir ~/.test && echo "abc" > ~/.test/file.html && xdg-open ~/.test/file.html

I couldn't find any reference for this behaviour in RFC8089, and I also don't understand how the Jupyter authors missed this issue.

As LSeu suggested, the way to bypass the local redirection file, is to run: echo "c.NotebookApp.use_redirect_file = False" >> ~/.jupyter/jupyter_notebook_config.py

Another solution is to run jupyter notebook --no-browser and (Ctrl)-click the link in the terminal.

Vevine answered 27/4, 2022 at 10:1 Comment(0)
I
1

For those running Firefox installed with snap:

I think this issue has more to do with firefox installed with Snap, which somewhere along the way disallows Firefox access to hidden directories inside the /home/user folder in its sandboxed environment.

Another solution not mentioned in this thread (if you don't want to use another browser install) is to set the JUPYTER_RUNTIME_DIR env variable to a non-hidden directory in the /home/user folder:

# Ubuntu 22.04.1 LTS
# append env variable to persistent user env file.  requires relogging in
echo JUPYTER_RUNTIME_DIR=/home/user/jupyter_runtime >> ~/.pam_environment
reboot
Interdependent answered 25/8, 2022 at 21:42 Comment(0)
I
1

Alternatively, try going directly to the other suggested URLs: http://localhost:8888/lab?token=<your-access-token> or http://127.0.0.1:8888/lab?token=<your-access-token> (which is what setting the ...use_redirect_file = False does)

If answered 6/9, 2022 at 15:0 Comment(1)
This is the only solution that worked. I even reinstall conda (and looked at many other options). Thanks for this!Repute
T
0

I resolved this issue in my Windows 11 PC by doing this:

  • Go to "Windows Defender Security Center"
  • Scroll & Click on "Virus & threat protection settings"
  • Scroll down to "Controlled folder
    access" enable it
  • Select "Allow an app though Controlled folder
    access"
  • Click "Add and allowed app" and choose the file "C:\ProgramData\anaconda3\pythonw.exe"

enter image description here

Teenager answered 6/7 at 1:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.