简体   繁体   English

Jupyter Notebook:访问文件被拒绝

[英]Jupyter Notebook: Access to the file was denied

I'm trying to run a Jupyter notebook on Ubuntu 21.10.我正在尝试在 Ubuntu 21.10 上运行 Jupyter 笔记本。 I've installed python, jupyter notebook, and all the various prerequisites.我已经安装了 python、jupyter notebook 和所有各种先决条件。 I added export PATH=$PATH:~/.local/bin to my bashrc so that the command jupyter notebook would be operational from the terminal.我将export PATH=$PATH:~/.local/bin添加到我的bashrc中,以便命令jupyter notebook可以从终端运行。

When I call jupyter notebook from the terminal, I get the following error message from my browser:当我从终端调用jupyter notebook时,我从浏览器收到以下错误消息:

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.我正在使用最新版本的 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.使用sudo没有帮助,实际上它会导致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.如果我将 go 连接到终端,而是单击笔记本服务器的localhost:8888或 IP 地址,那么它会将我带到笔记本电脑,一切运行都没有问题。

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.我想解决这个问题,这样当我运行jupyter notebook时,我被带到服务器,不需要 go 回到终端 window 并单击 IP 地址。 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 Ubuntu 20.04.3 LTS 铬版 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:编辑配置文件~/.jupyter/jupyter_notebook_config.py并设置:

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否则,您可以清理并重新安装 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).如果有人好奇,问题的原因是file:// URI 方案无法直接访问主目录下的隐藏目录中的文件(在您的情况下为~/.local )。

You can recreate the problem with: mkdir ~/.test && echo "abc" > ~/.test/file.html && xdg-open ~/.test/file.html您可以使用以下命令重新创建问题: 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.我在RFC8089中找不到此行为的任何参考资料,而且我也不明白 Jupyter 作者是如何错过这个问题的。

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正如 LSeu 建议的那样,绕过本地重定向文件的方法是运行: 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.另一种解决方案是运行jupyter notebook --no-browser并 (Ctrl)-单击终端中的链接。

Try this尝试这个

sudo nano  ~/.bashrc

Add at the begining of the file:在文件开头添加:

 export XDG_RUNTIME_DIR="" 

Press Ctrl-o to write file and Ctrl+x to exit.按 Ctrl-o 写入文件,按 Ctrl+x 退出。

Now type:现在输入:

source ~/.bashrc

For those running Firefox installed with snap:对于那些运行 Firefox 并安装了 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.我认为这个问题与安装了 Snap 的 firefox 有更多关系,在此过程中某处不允许 Firefox 访问其沙盒环境中 /home/user 文件夹内的隐藏目录。

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:此线程中未提及的另一个解决方案(如果您不想使用其他浏览器安装)是将JUPYTER_RUNTIME_DIR变量设置为/home/user文件夹中的非隐藏目录:

# 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或者,尝试直接访问其他建议的 URL: http://localhost:8888/lab?token=<your-access-token>http://127.0.0.1:8888/lab?token=<your-access-token> (这是设置...use_redirect_file = False所做的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Jupyter Notebook 中授予文件处理访问权限? [权限被拒绝错误] - How to grant Access for File Handling in Jupyter Notebook? [Permission Denied Error] Jupyter Notebook Windows 10 访问被拒绝 - Jupyter Notebook Windows 10 Access Denied Jupyter:在 spyder / jupyter notebook 中启动内核时访问被拒绝错误 - Jupyter: Access denied error when starting kernel in spyder / jupyter notebook Jupyter Notebook:cmd 错误访问被拒绝 (Windows 10) - Jupyter Notebook: cmd error access denied (Windows 10) 在 Jupyter Notebook 仪表板中意外拒绝终端访问我的 Documents 文件夹 - Accidentally denied Terminal access to my Documents folder in Jupyter Notebook dashboard 无法访问主目录中的文件(Jupyter Notebook) - Unable to access file in home directory (Jupyter Notebook) Docker 上的 Jupyter 笔记本 - 权限被拒绝 - Jupyter notebook on Docker - permission denied 如何在Jupyter Notebook中作为依赖项包访问tar / zip文件 - How to access a tar/zip file in Jupyter notebook as a dependency package 如何在 jupyter notebook 中将一个 ipynb 文件中定义的变量访问到另一个文件中? - How to access variables defined in one ipynb file into another in jupyter notebook? 为什么使用 Jupyter Notebook 无法访问 Google Drive 文件夹中的文件? - Why cannot access file in Google Drive folder by using Jupyter Notebook?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM