nbconvert: Permission denied problem with nbconvert

I have a conda installation of jupyter and, after a recent update, my ability to export and otherwise convert jupyter notebooks has been curtailed. For instance, I’m having the following problem at the command line:

guardian@titan:scratch$ jupyter nbconvert --to html mynotebook.ipynb 
Traceback (most recent call last):
  File "/Users/guardian/miniconda3/bin/jupyter-nbconvert", line 7, in <module>
    from nbconvert.nbconvertapp import main
  File "/Users/guardian/miniconda3/lib/python3.7/site-packages/nbconvert/nbconvertapp.py", line 140, in <module>
    class NbConvertApp(JupyterApp):
  File "/Users/guardian/miniconda3/lib/python3.7/site-packages/nbconvert/nbconvertapp.py", line 225, in NbConvertApp
    """.format(formats=get_export_names()))
  File "/Users/guardian/miniconda3/lib/python3.7/site-packages/nbconvert/exporters/base.py", line 141, in get_export_names
    e = get_exporter(exporter_name)(config=config)
  File "/Users/guardian/miniconda3/lib/python3.7/site-packages/nbconvert/exporters/base.py", line 102, in get_exporter
    if getattr(exporter(config=config), 'enabled', True):
  File "/Users/guardian/miniconda3/lib/python3.7/site-packages/nbconvert/exporters/templateexporter.py", line 328, in __init__
    super().__init__(config=config, **kw)
  File "/Users/guardian/miniconda3/lib/python3.7/site-packages/nbconvert/exporters/exporter.py", line 114, in __init__
    self._init_preprocessors()
  File "/Users/guardian/miniconda3/lib/python3.7/site-packages/nbconvert/exporters/templateexporter.py", line 494, in _init_preprocessors
    conf = self._get_conf()
  File "/Users/guardian/miniconda3/lib/python3.7/site-packages/nbconvert/exporters/templateexporter.py", line 512, in _get_conf
    if conf_path.exists():
  File "/Users/guardian/miniconda3/lib/python3.7/pathlib.py", line 1361, in exists
    self.stat()
  File "/Users/guardian/miniconda3/lib/python3.7/pathlib.py", line 1183, in stat
    return self._accessor.stat(self)
PermissionError: [Errno 13] Permission denied: '/usr/local/share/jupyter/nbconvert/templates/conf.json'

About this issue

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

Commits related to this issue

Most upvoted comments

This Permission error is caused due to the version of nbconvert. nbconvert 6.1.0 was the reason for this error. I have downgraded the nbconvert to 5.6.1 and it fixed the issue for me. I no longer face the Permission error any more while trying to open .ipynb files.

I thing the solution is to change the permissions on recursively /usr/local/share/jupyter/ to 0755 and the permissions of the files within the nbconvert folder to 0644 and the executables to 0655.

This feels pretty ugly, but will probably solve your problem.

You can use the find command to do this:

# change the permissions on the directories to group, other read and execute
$ find ./ -type d -exec chmod go+rx {} \;

# change all the other files to group, other read
$ find ./ -type f -exec chmod  go+r {} \;

# change all the executables to group, other execute
$ find ./ -type f -perm -100 -exec chmod go+x {} \;

I administer jupyterhub/lab for two separate institutions, and this has bit us both places. As @k-nayak helpfully points out, the workaround is to downgrade to 5.6.1 (thanks!), but I would recommend this issue re-open as it’s a significant break for multi-user applications of this.

If there are other people who still hit this with the 6.2 release - in our case this happens when we’re converting some notebooks in our CI which runs in a sandbox and can’t access /usr. We fixed it with the patch below.

diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py
index a3991b87..47cf59ed 100644
--- a/nbconvert/exporters/templateexporter.py
+++ b/nbconvert/exporters/templateexporter.py
@@ -516,9 +516,12 @@ class TemplateExporter(Exporter):
         conf = {}  # the configuration once all conf files are merged
         for path in map(Path, self.template_paths):
             conf_path = path / 'conf.json'
-            if conf_path.exists():
-                with conf_path.open() as f:
-                    conf = recursive_update(conf, json.load(f))
+            try:
+                if conf_path.exists():
+                    with conf_path.open() as f:
+                        conf = recursive_update(conf, json.load(f))
+            except PermissionError:
+                continue
         return conf
 
     @default('template_paths')

Investigating this, nbconvert 5.6 stores its templates in site-packages:

        "lib/python3.9/site-packages/nbconvert/templates/README.md",
        "lib/python3.9/site-packages/nbconvert/templates/asciidoc.tpl",
        "lib/python3.9/site-packages/nbconvert/templates/html/basic.tpl",
        "lib/python3.9/site-packages/nbconvert/templates/html/celltags.tpl",
        "lib/python3.9/site-packages/nbconvert/templates/html/full.tpl",
        "lib/python3.9/site-packages/nbconvert/templates/html/mathjax.tpl",
        "lib/python3.9/site-packages/nbconvert/templates/html/slides_reveal.tpl",
        "lib/python3.9/site-packages/nbconvert/templates/latex/article.tplx",
        "lib/python3.9/site-packages/nbconvert/templates/latex/base.tplx",
        "lib/python3.9/site-packages/nbconvert/templates/latex/document_contents.tplx",
        "lib/python3.9/site-packages/nbconvert/templates/latex/report.tplx",
        "lib/python3.9/site-packages/nbconvert/templates/latex/skeleton/display_priority.tplx",
        "lib/python3.9/site-packages/nbconvert/templates/latex/skeleton/null.tplx",
        "lib/python3.9/site-packages/nbconvert/templates/latex/style_bw_ipython.tplx",
        "lib/python3.9/site-packages/nbconvert/templates/latex/style_bw_python.tplx",
        "lib/python3.9/site-packages/nbconvert/templates/latex/style_ipython.tplx",
        "lib/python3.9/site-packages/nbconvert/templates/latex/style_jupyter.tplx",
        "lib/python3.9/site-packages/nbconvert/templates/latex/style_python.tplx",
        "lib/python3.9/site-packages/nbconvert/templates/markdown.tpl",
        "lib/python3.9/site-packages/nbconvert/templates/python.tpl",
        "lib/python3.9/site-packages/nbconvert/templates/rst.tpl",
        "lib/python3.9/site-packages/nbconvert/templates/script.tpl",
        "lib/python3.9/site-packages/nbconvert/templates/skeleton/README.md",
        "lib/python3.9/site-packages/nbconvert/templates/skeleton/display_priority.tpl",
        "lib/python3.9/site-packages/nbconvert/templates/skeleton/null.tpl",

while nbconvert 6.1 stores its templates in the share directory:

        "share/jupyter/nbconvert/templates/asciidoc/conf.json",
        "share/jupyter/nbconvert/templates/asciidoc/index.asciidoc.j2",
        "share/jupyter/nbconvert/templates/base/celltags.j2",
        "share/jupyter/nbconvert/templates/base/display_priority.j2",
        "share/jupyter/nbconvert/templates/base/jupyter_widgets.html.j2",
        "share/jupyter/nbconvert/templates/base/mathjax.html.j2",
        "share/jupyter/nbconvert/templates/base/null.j2",
        "share/jupyter/nbconvert/templates/basic/conf.json",
        "share/jupyter/nbconvert/templates/basic/index.html.j2",
        "share/jupyter/nbconvert/templates/classic/base.html.j2",
        "share/jupyter/nbconvert/templates/classic/conf.json",
        "share/jupyter/nbconvert/templates/classic/index.html.j2",
        "share/jupyter/nbconvert/templates/classic/static/style.css",
        "share/jupyter/nbconvert/templates/compatibility/display_priority.tpl",
        "share/jupyter/nbconvert/templates/compatibility/full.tpl",
        "share/jupyter/nbconvert/templates/lab/base.html.j2",
        "share/jupyter/nbconvert/templates/lab/conf.json",
        "share/jupyter/nbconvert/templates/lab/index.html.j2",
        "share/jupyter/nbconvert/templates/lab/static/index.css",
        "share/jupyter/nbconvert/templates/lab/static/theme-dark.css",
        "share/jupyter/nbconvert/templates/lab/static/theme-light.css",
        "share/jupyter/nbconvert/templates/latex/base.tex.j2",
        "share/jupyter/nbconvert/templates/latex/conf.json",
        "share/jupyter/nbconvert/templates/latex/display_priority.j2",
        "share/jupyter/nbconvert/templates/latex/document_contents.tex.j2",
        "share/jupyter/nbconvert/templates/latex/index.tex.j2",
        "share/jupyter/nbconvert/templates/latex/null.j2",
        "share/jupyter/nbconvert/templates/latex/report.tex.j2",
        "share/jupyter/nbconvert/templates/latex/style_bw_ipython.tex.j2",
        "share/jupyter/nbconvert/templates/latex/style_bw_python.tex.j2",
        "share/jupyter/nbconvert/templates/latex/style_ipython.tex.j2",
        "share/jupyter/nbconvert/templates/latex/style_jupyter.tex.j2",
        "share/jupyter/nbconvert/templates/latex/style_python.tex.j2",
        "share/jupyter/nbconvert/templates/markdown/conf.json",
        "share/jupyter/nbconvert/templates/markdown/index.md.j2",
        "share/jupyter/nbconvert/templates/python/conf.json",
        "share/jupyter/nbconvert/templates/python/index.py.j2",
        "share/jupyter/nbconvert/templates/reveal/base.html.j2",
        "share/jupyter/nbconvert/templates/reveal/conf.json",
        "share/jupyter/nbconvert/templates/reveal/index.html.j2",
        "share/jupyter/nbconvert/templates/reveal/static/custom_reveal.css",
        "share/jupyter/nbconvert/templates/rst/conf.json",
        "share/jupyter/nbconvert/templates/rst/index.rst.j2",
        "share/jupyter/nbconvert/templates/script/conf.json",
        "share/jupyter/nbconvert/templates/script/script.j2",
        "share/jupyter/nbconvert/templates/webpdf/conf.json",
        "share/jupyter/nbconvert/templates/webpdf/index.pdf.j2"

Plenty of Jupyter packages store data in the share/jupyter directory (e.g., JupyterLab, Jupyter Notebook, IPython kernel spec, etc.). Putting files there is not out of the ordinary at all. The files in that share/jupyter directory should be readable to function.

If you install, for example, JupyterLab, Jupyter Notebook, ipywidgets, etc. in the same way, are their share/jupyter files also unreadable?

Hi @gideonsimpson , I found that if I install jupyterhub and jupyterlab using conda with root, the permission of /usr/local/share/jupyter/nbconvert/templates will be 0700, and other users without root will not be able to write conf.json into this dir. I think this is because nbconvert was not designed for multi-user initially like jupyterhub. Will there be a plan to add multi-user support for nbconvert?

After reviewing the two PRs #1028 and #1056, I think we can just remove this code. I’ve done this in https://github.com/jupyter/nbconvert/pull/1646, ready for review.

@jasongrout it seems that the culprit is this snippet:

https://github.com/jupyter/nbconvert/blob/4607ed2078f38a63d055e76307d9f66f32e8a5fd/nbconvert/exporters/templateexporter.py#L550-L555

and more specifically the call to ensure_dir_exists. It causes the creation of an empty templates folder for all levels of additional_paths some of which may be system libraries.

I have this problem as well and downgrading worked but is never the best solution

what are the permissions on the /usr/local/share/jupyter/nbconvert/templates/ directory?

try: ls -alh /usr/local/share/jupyter/nbconvert/templates/ and ls -alh /usr/local/share/jupyter/nbconvert/templates/conf.json