danielfrg / mkdocs-jupyter

Use Jupyter Notebook in mkdocs
https://mkdocs-jupyter.danielfrg.com
Apache License 2.0
367 stars 45 forks source link

Demo not working with fresh venv #152

Closed dsgibbons closed 9 months ago

dsgibbons commented 1 year ago

I was having issues getting this to work with my own project so I ran the following commands to test the demo on Ubuntu 20.04 with Python 3.10.6:

git clone https://github.com/danielfrg/mkdocs-jupyter.git
cd mkdocs-jupyter/
python -m venv venv --prompt .
source venv/bin/activate
pip install .
cd demo
mkdocs serve

and I receive the following error:

INFO     -  DeprecationWarning: Jupyter is migrating its paths to use standard platformdirs
            given by the platformdirs library.  To remove this warning and
            see the appropriate new directories, set the environment variable
            `JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`.
            The use of platformdirs will be the default in `jupyter_core` v6
              File
            "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/jupyter_core/utils/__init__.py",
            line 89, in deprecation
                warnings.warn(message, DeprecationWarning, stacklevel=stacklevel + 1)
              File
            "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/jupyter_client/connect.py",
            line 20, in
                from jupyter_core.paths import jupyter_data_dir, jupyter_runtime_dir, secure_write
INFO     -  Building documentation...
INFO     -  Cleaning site directory
INFO     -  The following pages exist in the docs directory, but are not included in the "nav"
            configuration:
              - fail.ipynb
INFO     -  Converting notebook (execute=False):
            /home/daniel/code/mkdocs-jupyter/demo/docs/demo-nb-md.ipynb
ERROR    -  Error reading page 'demo-nb-md.ipynb': mkdocs_html/assets/mkdocs-jupyter.css
Traceback (most recent call last):
  File "/home/daniel/code/mkdocs-jupyter/venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/mkdocs/__main__.py", line 234, in serve_command
    serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/mkdocs/commands/serve.py", line 83, in serve
    builder(config)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/mkdocs/commands/serve.py", line 76, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/mkdocs/commands/build.py", line 308, in build
    _populate_page(file.page, config, files, dirty)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/mkdocs/commands/build.py", line 181, in _populate_page
    page.render(config, files)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/mkdocs_jupyter/plugin.py", line 107, in new_render
    body = convert.nb2html(
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/mkdocs_jupyter/nbconvert2.py", line 150, in nb2html
    content, resources = exporter.from_filename(
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/nbconvert/exporters/templateexporter.py", line 388, in from_filename
    return super().from_filename(filename, resources, **kw)  # type:ignore
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/nbconvert/exporters/exporter.py", line 201, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/nbconvert/exporters/templateexporter.py", line 394, in from_file
    return super().from_file(file_stream, resources, **kw)  # type:ignore
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/nbconvert/exporters/exporter.py", line 220, in from_file
    return self.from_notebook_node(
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/nbconvert/exporters/html.py", line 234, in from_notebook_node
    return super().from_notebook_node(nb, resources, **kw)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/nbconvert/exporters/templateexporter.py", line 426, in from_notebook_node
    output = self.template.render(nb=nb_copy, resources=resources)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/mkdocs_jupyter/templates/mkdocs_html/notebook.html.j2", line 82, in top-level template code
    {%- set vars = {"cell_id": 0 } -%}
  File "/home/daniel/code/mkdocs-jupyter/venv/share/jupyter/nbconvert/templates/lab/index.html.j2", line 3, in top-level template code
    {% from 'jupyter_widgets.html.j2' import jupyter_widgets %}
  File "/home/daniel/code/mkdocs-jupyter/venv/share/jupyter/nbconvert/templates/lab/base.html.j2", line 3, in top-level template code
    {% from 'cell_id_anchor.j2' import cell_id_anchor %}
  File "/home/daniel/code/mkdocs-jupyter/venv/share/jupyter/nbconvert/templates/base/display_priority.j2", line 1, in top-level template code
    {%- extends 'base/null.j2' -%}
  File "/home/daniel/code/mkdocs-jupyter/venv/share/jupyter/nbconvert/templates/base/null.j2", line 24, in top-level template code
    {%- block header -%}
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/mkdocs_jupyter/templates/mkdocs_html/notebook.html.j2", line 49, in block 'header'
    {% block notebook_css %}
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/mkdocs_jupyter/templates/mkdocs_html/notebook.html.j2", line 51, in block 'notebook_css'
    {{ resources.include_css("mkdocs_html/assets/mkdocs-jupyter.css") }}
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/nbconvert/exporters/html.py", line 239, in resources_include_css
    code = """<style type="text/css">\n%s</style>""" % (env.loader.get_source(env, name)[0])
  File "/home/daniel/code/mkdocs-jupyter/venv/lib/python3.10/site-packages/jinja2/loaders.py", line 561, in get_source
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: mkdocs_html/assets/mkdocs-jupyter.css
moble commented 1 year ago

This isn't precisely the same failure I saw, but it looks likely to be the same. See #154 for a workaround.

danielfrg commented 9 months ago

This should be fixed in newer versions.