Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nbconvert export fails for HTML & PDF on macOS with Python-Homebrew-Installation #1773

Closed
guger opened this issue May 10, 2022 · 14 comments
Closed

Comments

@guger
Copy link

guger commented May 10, 2022

Description
I want to export a pdf of my jupyter notebook (.ipynb) file, but this doesn't work, as it can't resolve the template_path.

Stacktrace:

jupyter nbconvert --to html SymMeasNodeNet.ipynb
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/traitlets/traitlets.py", line 537, in get
    value = obj._trait_values[self.name]
KeyError: 'template_paths'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/bin/jupyter-nbconvert", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/jupyter_core/application.py", line 269, in launch_instance
    return super().launch_instance(argv=argv, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/traitlets/config/application.py", line 846, in launch_instance
    app.start()
  File "/opt/homebrew/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 414, in start
    self.convert_notebooks()
  File "/opt/homebrew/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 582, in convert_notebooks
    cls = get_exporter(self.export_format)
  File "/opt/homebrew/lib/python3.9/site-packages/nbconvert/exporters/base.py", line 101, in get_exporter
    if getattr(exporter(config=config), "enabled", True):
  File "/opt/homebrew/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 341, in __init__
    super().__init__(config=config, **kw)
  File "/opt/homebrew/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 117, in __init__
    self._init_preprocessors()
  File "/opt/homebrew/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 507, in _init_preprocessors
    conf = self._get_conf()
  File "/opt/homebrew/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 525, in _get_conf
    for path in map(Path, self.template_paths):
  File "/opt/homebrew/lib/python3.9/site-packages/traitlets/traitlets.py", line 577, in __get__
    return self.get(obj, cls)
  File "/opt/homebrew/lib/python3.9/site-packages/traitlets/traitlets.py", line 540, in get
    default = obj.trait_defaults(self.name)
  File "/opt/homebrew/lib/python3.9/site-packages/traitlets/traitlets.py", line 1580, in trait_defaults
    return self._get_trait_default_generator(names[0])(self)
  File "/opt/homebrew/lib/python3.9/site-packages/traitlets/traitlets.py", line 977, in __call__
    return self.func(*args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 536, in _template_paths
    template_names = self.get_template_names()
  File "/opt/homebrew/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 620, in get_template_names
    raise ValueError(
ValueError: No template sub-directory with name 'lab' found in the following paths:
	/Users/dguger/Library/Jupyter
	/Users/dguger/Library/Python/3.9/share/jupyter
	/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/share/jupyter
	/usr/local/share/jupyter
	/usr/share/jupyter

Can you list steps to reproduce this issue?

Try to export a file using nbconvert on macOS.

Environment Data:

  • OS: macOS Monterey 12.3.1
  • Python version: 3.9.12
  • Jupyter server running: Local
  • LaTeX version: MacTex Version 3.141592653 (TeX Live 2021)
  • nbconvert: 6.5.0
  • jupyter: 1.0.0
  • jupyter-core: 4.10.0
@guger
Copy link
Author

guger commented May 24, 2022

The issue is still present in v7.0.0rc1!

@hyt658
Copy link

hyt658 commented Jun 9, 2022

I have the same issue, hope can get solution soon :D

@guger
Copy link
Author

guger commented Jun 29, 2022

The error does also occur when using a venv. Every Python environment I use is based on a homebrew installation.

Does anybody know if this is a homebrew-specific error or does anybody also experience this on non-homebrew installations of Python on macOS?

What is your installation method and OS? @hyt658

@hyt658
Copy link

hyt658 commented Jun 29, 2022

I installed via homebrew as well

@Mills-2
Copy link

Mills-2 commented Jul 25, 2022

Any updates on this?

@guger
Copy link
Author

guger commented Aug 9, 2022

6.5.1 does not change anything...

@PaleNeutron
Copy link

Any updates on it? I found a tmp workaround

And this bug breaks my projects test

@bartoli
Copy link

bartoli commented Sep 23, 2022

As mentionned in the last linked issue, i am getting the error after jupyter has been installed using 'pip install jupyter --prefix=XXXX'. Templates are properly installed, but in XXXX/jupyter/share/nbconvert/templates, and i guess they are searched in PYTHON_ROOT/share/... ?

@bartoli
Copy link

bartoli commented Oct 5, 2022

In my case, this is 'fixed' by adding

root_dirs.append(os.path.abspath(os.path.join(ROOT, "..", "..", "..", "..", "share", "jupyter")))

to get_prefix_root_dirs() in nbconvert/exporters/templateexporter.py.

Worst case, this adds a folder that is a duplicate of PYTHON_ROOT/share/jupyter if it is a standard install. A 'smart' condition could be added to avoid adding it if we detect that we are installed in python folder. Or this path could replace PYTHON_ROOT/share/jupyter in the list alltogether?

@GabeNicholson
Copy link

Still having this issue with the most recent version with M1 Mac and home-brew. Not sure if there are any known fixes?

bartoli added a commit to bartoli/nbconvert that referenced this issue Oct 14, 2022
For issue nbconvert jupyter#1773.
Look for the standard templates folder using their expected relative path compared to the existing script. When jupyter is installed using pip install jupyter --prefix=XXX,  root_dirs did not contain XXX/share/jupyter as candidate.
Maybe even jupyter_path() should be updated instead to potentially fix other places? I don't know the project enough to decide
@guger
Copy link
Author

guger commented Oct 15, 2022

@bartoli Unfortunately, #1880 does not solve the issue for me.

In my case:
root_dirs.append(os.path.abspath(os.path.join(ROOT, "..", "..", "..", "..", "..", "share", "jupyter")))
is needed instead of
root_dirs.append(os.path.abspath(os.path.join(ROOT, "..", "..", "..", "..", "share", "jupyter")))

@kgrodzicki
Copy link

kgrodzicki commented Oct 19, 2022

Still having this issue with the most recent version with M1 Mac and home-brew. Not sure if there are any known fixes?

Extending the JUPYTER_PATH with /opt/homebrew/share/jupyter solves the problem.

export JUPYTER_PATH=/opt/homebrew/share/jupyter:$JUPYTER_PATH

@guger guger changed the title nbconvert export fails for HTML & PDF on macOS Monterey 12.3.1 nbconvert export fails for HTML & PDF on macOS with Python-Homebrew-Installation Oct 19, 2022
@guger
Copy link
Author

guger commented Apr 11, 2023

@kgrodzicki Thanks, that fixes the problem, but not the cause.
Works for me, though.

@guger guger closed this as completed Apr 11, 2023
@LPascholatti
Copy link

@kgrodzicki the workaround helped me! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants