nbconvert icon indicating copy to clipboard operation
nbconvert copied to clipboard

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

Open kpoman opened this issue 2 years ago • 16 comments

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

kpoman avatar Sep 14 '22 11:09 kpoman

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

bollwyvl avatar Sep 14 '22 14:09 bollwyvl

Same problem although running nbconvert 7.0.0 mistune 2.0.4

from nbconvert.exporters.base import get_export_names, get_exporter
      File "C:\Users\atosato\Miniconda3\lib\site-packages\nbconvert\__init__.py", line 4, in <module>
        from .exporters import *
      File "C:\Users\atosato\Miniconda3\lib\site-packages\nbconvert\exporters\__init__.py", line 3, in <module>
        from .html import HTMLExporter
      File "C:\Users\atosato\Miniconda3\lib\site-packages\nbconvert\exporters\html.py", line 25, in <module>
        from nbconvert.filters.highlight import Highlight2HTML
      File "C:\Users\atosato\Miniconda3\lib\site-packages\nbconvert\filters\__init__.py", line 6, in <module>
        from .markdown import *
      File "C:\Users\atosato\Miniconda3\lib\site-packages\nbconvert\filters\markdown.py", line 13, in <module>
        from .markdown_mistune import markdown2html_mistune
      File "C:\Users\atosato\Miniconda3\lib\site-packages\nbconvert\filters\markdown_mistune.py", line 40, in <module>
        class MathBlockGrammar(mistune.BlockGrammar):
    AttributeError: module 'mistune' has no attribute 'BlockGrammar'

albe-jj avatar Sep 27 '22 12:09 albe-jj

same as albe-jj

TomBugnon avatar Sep 27 '22 13:09 TomBugnon

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`

bollwyvl avatar Sep 27 '22 13:09 bollwyvl

As we said we are using nbconvert==7.0.0 and mistune==2.0.4

TomBugnon avatar Sep 27 '22 14:09 TomBugnon

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.

bollwyvl avatar Sep 27 '22 14:09 bollwyvl

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?

Flying-Tiantian avatar Oct 11 '22 07:10 Flying-Tiantian

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.

Flying-Tiantian avatar Oct 11 '22 07:10 Flying-Tiantian

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

markus-flicke avatar Jan 10 '23 09:01 markus-flicke

Echoing other comments that I've also run into this today. Reinstalling nbconvert and mistune (mamba install -c conda-forge nbconvert mistune) seemed to fix this.

Zeitsperre avatar Jan 11 '23 18:01 Zeitsperre

Appears to be the same problem. I updated anaconda and jupyter notebook gave me a 500 : Internal Server Error when opening a new notebook. I can see open up Jupyter notebook from anaconda navigator and see my files but when I try to open a new notebook or an existing notebook, I get the 500: Internal Server Error.

Jupyter lab seems to work fine.

I got this error when I attempted Zeitsperre's solution with pip in jupyter lab

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. jupyterhub 3.1.0 requires async-generator>=1.9, which is not installed. distributed 2022.7.0 requires tornado<6.2,>=6.0.3, but you have tornado 6.2 which is incompatible.

I installed async-generator 1.10 and that fixed the error message I got when installing nbconver and mistune but jupyter notebook still has the 500 error.

gtyellow avatar Jan 11 '23 21:01 gtyellow

@gtyellow did you find a fix? I have the same issue - updated anaconda navigator and now none of my notebooks are working. Getting the same 500: Internal Server Error.

jace-parkinson avatar Jan 26 '23 20:01 jace-parkinson

I had to go back a level on anaconda navigator. Tried a bunch of stuff to upgrade and downgrade jupyter notebook and python but it didn't work until I downgraded anaconda.

My current anaconda navigator version is 2.3.1 as of January 26, 2023 and I'm using it on Windows 11 version 21H2.

gtyellow avatar Jan 26 '23 21:01 gtyellow

I think this solution worked for me, though I have to say, as of 29th of January, before using this solution, conda asked me for update beforehand, maybe they fixed the incompatibility issue.

Kvitatiani avatar Jan 29 '23 11:01 Kvitatiani

suing conda install -c conda-forge 'nbconvert>=7' 'mistune>=2' fix this problem. at last: $ conda list nbconvert

packages in environment at /home/lwroot0/anaconda3/envs/lwp8:

Name Version Build Channel

nbconvert 7.9.2 pyhd8ed1ab_0 conda-forge nbconvert-core 7.9.2 pyhd8ed1ab_0 conda-forge nbconvert-pandoc 7.9.2 pyhd8ed1ab_0 conda-forge $ conda list mistune

packages in environment at /home/lwroot0/anaconda3/envs/lwp8:

Name Version Build Channel

mistune 3.0.2 pypi_0 pypi

hanjing5024064 avatar Oct 10 '23 02:10 hanjing5024064

https://stackoverflow.com/a/76189658/13086128

RubTalha avatar May 03 '24 14:05 RubTalha

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`

worked for me

imdataboy avatar Sep 29 '24 23:09 imdataboy