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

Fix bug on nbconvert: No module named 'notebook.services' #1663

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jalsti
Copy link

@jalsti jalsti commented Jul 4, 2024

when running jupyter nbconvert --execute --allow-errors --to pdf myfile.ipynb an error occured:
"""
File "/home/user/.local/lib/python3.11/site-packages/jupyter_contrib_nbextensions/nbconvert_support/init.py", line 5, in
from .collapsible_headings import ExporterCollapsibleHeadings
File "/home/user/.local/lib/python3.11/site-packages/jupyter_contrib_nbextensions/nbconvert_support/collapsible_headings.py", line 6, in
from notebook.services.config import ConfigManager
ModuleNotFoundError: No module named 'notebook.services'
"""

This change updates collapsible_headings.py to use the correct import from jupyter_server.services.config import ConfigManager

when running `jupyter nbconvert --execute --allow-errors --to pdf myfile.ipynb` an error occured: 
"""
  File "/home/user/.local/lib/python3.11/site-packages/jupyter_contrib_nbextensions/nbconvert_support/__init__.py", line 5, in <module>
    from .collapsible_headings import ExporterCollapsibleHeadings
  File "/home/user/.local/lib/python3.11/site-packages/jupyter_contrib_nbextensions/nbconvert_support/collapsible_headings.py", line 6, in <module>
    from notebook.services.config import ConfigManager
ModuleNotFoundError: No module named 'notebook.services'
"""
This change updates `collapsible_headings.py` to use the correct import `from jupyter_server.services.config import ConfigManager`
@MichaelWoodc
Copy link

Just encountered this issue right now! Not sure what changed overnight. Thanks for jumping on it!

@rprilepskiy
Copy link

I just got the same issue! @jalsti, thanks for stepping in and contribution! I tried to implement your change manually. But I got another error when running jupyter nbconvert --to script myfile.ipynb:

Traceback (most recent call last):
  File "/home/user/.pyenv/versions/3.11.9/envs/py3_11/lib/python3.11/site-packages/jupyter_contrib_nbextensions/nbconvert_support/execute_time.py", line 11, in <module>
    import notebook._tz as nbtz
ModuleNotFoundError: No module named 'notebook._tz'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.pyenv/versions/3.11.9/envs/py3_11/bin/jupyter-nbconvert", line 5, in <module>
    from nbconvert.nbconvertapp import main
  File "/home/user/.pyenv/versions/3.11.9/envs/py3_11/lib/python3.11/site-packages/nbconvert/nbconvertapp.py", line 193, in <module>
    class NbConvertApp(JupyterApp):
  File "/home/user/.pyenv/versions/3.11.9/envs/py3_11/lib/python3.11/site-packages/nbconvert/nbconvertapp.py", line 252, in NbConvertApp
    Options include {get_export_names()}.
                     ^^^^^^^^^^^^^^^^^^
  File "/home/user/.pyenv/versions/3.11.9/envs/py3_11/lib/python3.11/site-packages/nbconvert/exporters/base.py", line 145, in get_export_names
    e = get_exporter(exporter_name)(config=config)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.pyenv/versions/3.11.9/envs/py3_11/lib/python3.11/site-packages/nbconvert/exporters/base.py", line 106, in get_exporter
    exporter = items[0].load()
               ^^^^^^^^^^^^^^^
  File "/home/user/.pyenv/versions/3.11.9/lib/python3.11/importlib/metadata/__init__.py", line 202, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.pyenv/versions/3.11.9/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.pyenv/versions/3.11.9/envs/py3_11/lib/python3.11/site-packages/jupyter_contrib_nbextensions/nbconvert_support/__init__.py", line 7, in <module>
    from .execute_time import ExecuteTimePreprocessor
  File "/home/user/.pyenv/versions/3.11.9/envs/py3_11/lib/python3.11/site-packages/jupyter_contrib_nbextensions/nbconvert_support/execute_time.py", line 14, in <module>
    import notebook.services.contents.tz as nbtz
ModuleNotFoundError: No module named 'notebook.services'

It seems that there should be some other changes in
/site-packages/jupyter_contrib_nbextensions/nbconvert_support/execute_time.py:

Before:
[line 11] import notebook._tz as nbtz

After:
[line 11] import jupyter_server._tz as nbtz

After that my ipynb converting was successful.

Just in case:

jupyter_contrib_nbextensions      0.7.0
jupyter_server                    2.14.2
nbconvert                         7.16.4
notebook                          7.2.1

@darthoctopus
Copy link

applying this and @rprilepskiy's changes fixed this issue for me too

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

Successfully merging this pull request may close these issues.

4 participants