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 AttributeError: module 'mistune' has no attribute 'BlockGrammar' #1864

Open
kpoman opened this issue Sep 14, 2022 · 16 comments
Open

Comments

@kpoman
Copy link

kpoman commented Sep 14, 2022

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

@bollwyvl
Copy link
Contributor

bollwyvl commented Sep 14, 2022 via email

@albe-jj
Copy link

albe-jj commented Sep 27, 2022

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'

@TomBugnon
Copy link

same as albe-jj

@bollwyvl
Copy link
Contributor

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`

@TomBugnon
Copy link

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

@bollwyvl
Copy link
Contributor

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.

@Flying-Tiantian
Copy link

Flying-Tiantian commented Oct 11, 2022

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
Copy link

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.

@markus-flicke
Copy link

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

@Zeitsperre
Copy link

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.

@gtyellow
Copy link

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.

@jace-parkinson
Copy link

@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.

@gtyellow
Copy link

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.

@Kvitatiani
Copy link

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.

@hanjing5024064
Copy link

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

@RubTalha
Copy link

RubTalha commented May 3, 2024

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

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

13 participants