Jupyter Notebook: Access to the file was denied - python

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!

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

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.

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

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)

Related

Jupyter notebook won't launch after writing "jupyter notebook" in terminal

I have been searching this problem since a while, but can't find a solution. I am working in Windows 10.
After I activate any virtual environment and I write "jupyter notebook", the terminal gets stucked and nothing happens, like in the picture:
No errors appear, I can't Ctrl+C to kill terminal and no browser page appears.
The "jupyter --help" command works, but any other subcommand (like jupyter lab, jupyter nbclassic or jupyter run) doesn't
I tried to do the following, with no results:
Uninstall and install jupyter again
I tried to lunch jupyter notebook with Anaconda Navigator
I tried to open a browser and go to "http://localhost:8889/tree", using different port values
I tried to restart my laptop
Does anyone have any idea what is going on?
Well,
If you've re-installed Anaconda with the default settings, it should set up PATH correctly. So I hope the error is not with PATH environment variable
Try the following:
If Jupyter gives an error that it can’t find notebook, check with pip or conda that the notebook package is installed.
Try running jupyter-notebook (with a hyphen). This should normally be the same as jupyter notebook (with a space), but if there’s any difference, the version with the hyphen is the ‘real’ launcher, and the other one wraps that.
It turned out that jupyter notebook was not starting because I could not ping my localhost (127.0.0.1) because of some bad network settings.
After running netsh winsock reset in a cmd terminal to reset the network settings, I could ping the localhost and jupyter notebook started to work again.

Error loading Jupyter Notebook from a child directory

Since I have updated to macOS Big Sur (I have managed to fix all of the Python issues that Big Sur created on my computer. This article is helpful for that), I've been unable to open the Jupyter Notebooks in any of the child directories of where I start my Jupyter Notebook.
I can however open notebooks in the same directory as where I had started my Jupyter Notebook instance.
Here is a screenshot of the error message:
Here also is the error message I get in the terminal when trying to open a new notebook in a child directory:
[W 20:18:51.458 NotebookApp] 404 GET /nbextensions/widgets/notebook/js/extension.js?v=20210723201825 (::1) 2.560000ms referer=http://localhost:8888/notebooks/0001_analysis/Untitled2.ipynb?kernel_name=python3
I use pyenv and poetry to manage my python environment and packages. I have the local version of python set to Python 3.8.2.
Here are my poetry dependencies in my pyproject.toml:
[tool.poetry.dependencies]
python = "^3.8
[tool.poetry.dev-dependencies]
pandas = "^1.3.0"
scikit-learn = "^0.24.2"
jupyter = "^1.0.0"
seaborn = "^0.11.1"
ipykernel = "^6.0.1"
Would be great to fix this, as it is inconvenient having to create new notebook instances when I need to open notebooks in different child directories of my project.
This may be system integrity protection, though I've seen it in Catalina before, did you leapfrog a version ?
If you are starting Jupyter from the terminal, try the following:
Open a new terminal, , type cd (with a space) and drag and drop the folder you wish to start jupyter in to the terminal. You need to drag and drop, this will flag the folder as being "ok to be accessed from application launched from the terminal" typing the path by hand won't help. Press enter, and then try to start jupyter from there.
If you have any error message in the terminal they should be helpful, try to also open the .ipynb files with a text editor to make sure they are not corrupted, and/or share them with somebody else to see if they can open it.

pip3 install of Jupyter and Notebook problem when running

I have tried all of the things here on stack and on other sites with no joy...
I'd appreciate any suggestions please.
I have installed Jupyter and Notebook using pip3 - please note that I have updated pip3 before doing so.
However when trying to check the version of both jupyter --version and notebook --version my terminal is returning no command found. I have also tried to run jupyter, notebook and jupyter notebook and I am still getting the same message.
I have spent nearly two days now trying to sort this out... I'm on the verge of giving up.
I have a feeling it has something to do with my PATH variable maybe not pointing to where the jupyter executable is stored but I don't know how to find out where notebook and jupyter are stored on my system.
many thanks in advance
Bobby
You should be able to run jupyter with python -m even if the PATH variable is not set up correctly.
python -m jupyter notebook
you can check the PATH variables on Windows if you search in with the windows search function for env and then click on Edit the system environment variables > Environment Variables....
The path variable is a list of paths that the terminal checks for commands.
I didn`t work on Mac for a long time, so not sure how similar linux and mac command line still are, but on debian you control your path variable like this.
View paths:
echo $PATH
/usr/local/bin:/usr/bin:/bin
Add a path:
export PATH=$PATH:/mynewpath
For constant export add to ~/.bashrc
To view the path of the pip package, you can use
pip3 show jupyter
When jupyter-notebook works and jupyter notebook does not. It looks to me like a symlink thing. Or a Mac-specific problem.
So to summarise this is what I have found on this issue (in my experience):
to run the jupyter app you can use the jupyter-notebook command and this works, but why? This is because, the jupyter-notebook is stored in usr/local/bin which is normally always stored in the PATH variable.
I then discovered that the jupyter notebook or jupyter --version command will now work if I did the following:
open my ./bash_profile file
add the following to the bottom of the file: export PATH=$PATH:/Users/your-home-directory/Library/Python/3.7/bin
this should add the location of where jupyter is located to your path variable.
Alternatively, as suggested by #HackLab we can also do the following:
python3 -m jupyter notebook
Hopefully, this will give anyone else having the same issues I had an easier time resolving this issue.
I've found a solution from the documentation over at Jupyter https://jupyter-notebook.readthedocs.io/en/stable/troubleshooting.html but I am still curious.
It states that to run the application to use the command jupyter-notebook and hey-presto! It does seem to work now. But, why is this when nearly everywhere else I have read that to run the app we just type the command jupyter notebook.
Also, if I do need to check the version of any of the Jupyter files how do I go about this now, if jupyter --version and notebook --version still don't work.
Also, how do I go about finding these files in my file system if I have no idea where they are located? And how do I go about adding these to my path so that I can, for example, check the version of these programs?
Will pip3 automatically update this software as and when needed?
Thanks again in advance
have you tried locate Jupiter? It may tell you where jupyter is on your system.
Also, why not try installing jupyter via anaconda to avoid the hassle?
I definitely would recommend going through anaconda which makes everything a lot easier.
The following is the link with step by step instructions: https://jupyter.readthedocs.io/en/latest/install.html

Just installed Jupyter using Anaconda but can't run it using terminal. Says command not found

I just bought my very first Mac after using Windows my entire life and have been trying to install things. I am also still kind of a beginner at programming.
I installed Anaconda for Python 2.7 version, and then I installed the 3.7 version right after.
I tried going to terminal and typing jupyter notebook but it says:
zsh: command not found: jupyter
I am able to launch a jupyter notebook (I think) when I search for jupyter notebook in spotlight and executing the top hit.
I've been reading a lot on forums about this issue and see a lot of people talking about PATH which I am not really sure about.
I've seen people also post their which python information and theirs seem very different from mine:
which python3
usr/bin/python3
which python
usr/bin/python
Any help would be appreciated! Still learning how to set up this Mac. Thank you.
You might want to refer to this link https://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html
3.1.2. Change Jupyter Notebook startup folder (Mac OS)
To launch Jupyter Notebook App:
Click on spotlight, type terminal to open a terminal window.
Enter the startup folder by typing cd /some_folder_name.
Type jupyter notebook to launch the Jupyter Notebook App The notebook interface will appear in a new browser window or tab.
From what I can understand you are not changing to the startup directory of Jupyter.
You need to add jupyter to your path.
In your terminal, type in the following command:
export PATH="/PUT JUPYTER PATH HERE:$PATH"
Then try jupyter notebook
Reasoning: If installing using pip install --user, you must add the user-level bin directory to your PATH environment variable in order to launch jupyter lab

Anaconda-Jupyter Doesn't open in browser

I installed Anaconda 3.7 on Ubuntu 18.04 (Bionic Beaver). Installation was successful. When I tried to start Jupyter Notebook from navigator it throws the following error.
Access to the file was denied The file at
file:///run/user/1000/jupyter/nbserver-26395-open.html is not
readable. It may have been removed, moved or file permissions may be
preventing access.
For me, this worked on Raspberry Pi4, Ubuntu 20.04, with Chromium Browser.
Generate the config file with following command.
jupyter notebook --generate-config
Config file is created at ~/.jupyter directory
Look for parameter c.NotebookApp.use_redirect_file and set the same as False.
c.NotebookApp.use_redirect_file = False in order to disable launching browser by redirect file .
Explanation:
For versions of notebook > 5.7.2, a security feature measure was added
that prevented the authentication token used to launch the browser
from being visible. This feature makes it difficult for other users on
a multi-user system from running code in your Jupyter session as you.
However, some environments (like Windows Subsystem for Linux (WSL) and
Chromebooks), launching a browser using a redirect file can lead the
browser failing to load. This is because of the difference in file
structures/paths between the runtime and the browser.
Also make sure the ~/.local/share/jupyter and ~/.jupyter directories are owned by the user running jupyter
I think you have changed your default browser from Firefox to something else, Jupyter Notebook works fine on Firefox but throws permission denied on Chromium (for me). Just go to Setting > Details > Default Application and select FireFox in Web. Cheers
As shown in the image, jupyter notebook also provides a link. Try opening it with the browser of your choice. It worked for me...
With recent versions of snap, applications installed with snap can't by default open files in hidden folders (with a name starting by .).
In Ubuntu 20.04, chromium is installed with snap (even when using the command sudo apt install chromium-browser), so chromium can't open the html file used by Jupyter.
As stated by #rahul-sood, a simple workaround is to copy-paste one of the alternative links given by Jupyter in the terminal (starting by http://localhost:8889/?token= or http://127.0.0.1:8889/?token=).
For anyone interested in open jupyterlab or jupyter notebook in chrome : install it in the terminal with
sudo apt-get install google-chrome-stable
It didn't work for me by using chromium. And, as mentionned paugier, in Ubuntu 20.04, chromium is installed with snap (even when using the command sudo apt install chromium-browser), so chromium can't open the html file used by Jupyter. So if you install chrome by using the terminal it works.
Open Chrome and paste the Jupiter file path. In my case it's file:///home/vanx/.local/share/jupyter/runtime/nbserver-14511-open.html and it worked.

Categories