nbconvert: nbconvert AttributeError: module 'mistune' has no attribute 'BlockGrammar'

nbconvert 6.4.4 fails using mistune 2.0.4

Install/update your conda env to those versions (latest) and creating or accessing any notebook fails with this error:

        {% for exporter in get_frontend_exporters() %}
      File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\notebook\handlers.py", line 23, in get_frontend_exporters
        from nbconvert.exporters.base import get_export_names, get_exporter
      File "C:\ProgramData\Anaconda3\lib\site-packages\nbconvert\__init__.py", line 4, in <module>
        from .exporters import *
      File "C:\ProgramData\Anaconda3\lib\site-packages\nbconvert\exporters\__init__.py", line 3, in <module>
        from .html import HTMLExporter
      File "C:\ProgramData\Anaconda3\lib\site-packages\nbconvert\exporters\html.py", line 25, in <module>
        from nbconvert.filters.highlight import Highlight2HTML
      File "C:\ProgramData\Anaconda3\lib\site-packages\nbconvert\filters\__init__.py", line 6, in <module>
        from .markdown import *
      File "C:\ProgramData\Anaconda3\lib\site-packages\nbconvert\filters\markdown.py", line 13, in <module>
        from .markdown_mistune import markdown2html_mistune
      File "C:\ProgramData\Anaconda3\lib\site-packages\nbconvert\filters\markdown_mistune.py", line 40, in <module>
        class MathBlockGrammar(mistune.BlockGrammar):
    AttributeError: module 'mistune' has no attribute 'BlockGrammar'

Nbconvert version: 6.4.4

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 2
  • Comments: 15 (3 by maintainers)

Most upvoted comments

The 7.x line imports BlockParser, not BlockGrammar.

Please ensure you have installed the correct versions.

Modifying for your environment management approach, in the case of pip:

pip install --upgrade 'nbconvert>=7' 'mistune>=2'

Or conda.

conda install -c conda-forge 'nbconvert>=7' 'mistune>=2`

Reinstall nbconvert==7.2.1 with pip and Found existing installation: nbconvert 6.4.4 😥 Now everything works fine. But it is still weird because I setup the environment from a clean conda env.

I also had this error with: nbconvert==7.2.7 mistune 2.0.4

Solved by downgrading nbconvert to: nbconvert==7.2.1 mistune 2.0.4

Same problem with nbconvert==7.2.1 and mistune 2.0.4

When pip list shows nbconvert version number is 7.2.1, the _version.py file in installed pkg is:

version_info = (6, 4, 4)
pre_info = ''
dev_info = ''

def create_valid_version(release_info, epoch=None, pre_input='', dev_input=''):
    '''
    Creates a pep440 valid version of version number given a tuple integers
    and optional epoch, prerelease and developmental info.

    Parameters
    ----------
    release_info : Tuple(Int)
    epoch : Int, default None
    pre_input : Str, default ''
    dev_input : Str, default ''
    '''

    pep440_err = "The version number is not a pep 440 compliant version number"


    if epoch is not None:
        epoch_seg = str(epoch) + '!'
    else:
        epoch_seg = ''

    release_seg = '.'.join(map(str, release_info))

    _magic_pre =  ['a','b','rc']
    if pre_input!='' and not any([pre_input.startswith(prefix) for prefix in _magic_pre]):
        raise ValueError(pep440_err + "\n please fix your prerelease segment.")
    else:
        pre_seg = pre_input

    if dev_input=='':
        dev_seg = dev_input
    elif not dev_input.startswith('.') and dev_input.startswith('dev'):
        dev_seg = ''.join(['.', dev_input])
    elif dev_input.startswith('.dev'):
        dev_seg = dev_input
    elif dev_input!='':
        raise ValueError(pep440_err + "\n please fix your development segment.")

    if dev_input!='' and not any([dev_seg.endswith(str(n)) for n in range(10)]):
        dev_seg = ''.join([dev_seg,'0'])

    out_version = ''.join([epoch_seg, release_seg, pre_seg, dev_seg])


    import re
    def is_canonical(version):
        return re.match(r'^([1-9]\d*!)?(0|[1-9]\d*)'
                        r'(\.(0|[1-9]\d*))*((a|b|rc)(0|[1-9]\d*))?'
                        r'(\.post(0|[1-9]\d*))?(\.dev(0|[1-9]\d*))?$',
                        version
                        ) is not None

    if is_canonical(out_version):
        return out_version
    else:
        raise ValueError(pep440_err)


__version__ = create_valid_version(version_info, pre_input=pre_info, dev_input=dev_info)

Seems like the pkg on pypi is broken?

If you are seeing an AttributeError about BlockGrammar that string no longer appears in the pip or conda distributions.

You may have multiple, overlapping environments, user paths, PYTHONPATH, etc. that would also need to be upgraded.

The nbconvert 6.x line is not compatible with mistune >=2. Please upgrade to nbconvert 7.x.