【问题标题】:got a "Notebook error: PermissionError" while generating sphinx doc from jupyter notebook in virtualenv从 virtualenv 中的 jupyter notebook 生成 sphinx 文档时出现“笔记本错误:PermissionError”
【发布时间】:2019-12-13 10:38:59
【问题描述】:

我有一个可以使用或不使用 virtualenv 的 root 用户生成的笔记本,但作为标准用户生成时它会失败。

$ make html
reading sources... [100%] notebooks/demo_short                                                                                                                                                
Notebook error:
PermissionError in notebooks/demo_short.ipynb:
[Errno 13] Permission denied: '/usr/local/share/jupyter/nbconvert/templates/rst.tpl'
Makefile:19: recipe for target 'html' failed

$ sphinx-build -M html "." "_build" -v
[...]
  File "/home/with_home/p3/lib/python3.6/site-packages/jinja2/loaders.py", line 171, in get_source
    f = open_if_exists(filename)
  File "/home/with_home/p3/lib/python3.6/site-packages/jinja2/utils.py", line 154, in open_if_exists
    return open(filename, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/share/jupyter/nbconvert/templates/rst.tpl'

During handling of the above exception, another exception occurred:

[...]
  File "/home/with_home/p3/lib/python3.6/site-packages/docutils/readers/__init__.py", line 77, in parse
    self.parser.parse(self.input, document)
  File "/home/with_home/p3/lib/python3.6/site-packages/nbsphinx.py", line 869, in parse
    str(e))
nbsphinx.NotebookError: PermissionError in notebooks/demo_short.ipynb:
[Errno 13] Permission denied: '/usr/local/share/jupyter/nbconvert/templates/rst.tpl'

Notebook error:
PermissionError in notebooks/demo_short.ipynb:
[Errno 13] Permission denied: '/usr/local/share/jupyter/nbconvert/templates/rst.tpl'

我认为指示的路径是错误的,因为它应该指向我的 virtualenv 中的某个地方,但我不确定。

如果有帮助,我尝试了 virtualenv 中的命令 jupyter nbconvert notebooks/demo_short.ipynb。使用root,没问题,但使用标准用户,我有:

[...]
  File "/home/with_home/.local/lib/python3.6/site-packages/nbconvert/exporters/templateexporter.py", line 78, in get_source
    return self.loader.get_source(environment, template)
  File "/usr/lib/python3/dist-packages/jinja2/loaders.py", line 171, in get_source
    f = open_if_exists(filename)
  File "/usr/lib/python3/dist-packages/jinja2/utils.py", line 154, in open_if_exists
    return open(filename, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/share/jupyter/nbconvert/templates/html/full.tpl'

欢迎任何指针,因为我不知道 pb 是来自 sphinx、jupyter、nbconvert、nbsphinx 还是模板。

【问题讨论】:

    标签: templates jupyter-notebook virtualenv python-sphinx nbconvert


    【解决方案1】:

    将 nbconvert 降级到 5.6.1,为我修复了权限问题。

    【解决方案2】:

    您确定 nbconvert 在 /usr/local/share/jupyter/nbconvert 下吗? 我遇到了同样的问题。删除 /usr/local/share/jupyter/ 就行了。

    【讨论】:

    • 对我来说不是。你用过虚拟环境吗?我不明白为什么使用virtualenv,我在外面有东西。
    • 我做到了。尝试使用 --no-site-packages 创建您的 venv + 尝试使用 yourvenv/bin/pip 而不仅仅是“pip”来安装依赖项 + 在激活 venv 时检查 PYTHONPATH 的内容。此外,以 root 身份运行东西然后以普通用户身份运行可能不是一个好主意,因为它可能会创建普通用户不允许删除的文件。
    【解决方案3】:

    导航到 ~/.local/share/,使用 rm -rf Jupyter 删除 Jupyter 目录,然后再次尝试打开 jupyter notebook。

    【讨论】:

    • 还需要运行“jupyter lab build”
    • 我删除了这个,但它又重新创建了,同样的错误
    【解决方案4】:

    我只是在终端打印:

    sudo jupyter notebook --allow-root

    然后输入密码,Jupyter Notebook 就可以开始工作了。

    【讨论】:

      猜你喜欢
      • 2019-07-28
      • 1970-01-01
      • 2021-09-25
      • 2021-08-17
      • 2021-02-13
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      • 2021-06-05
      相关资源
      最近更新 更多