nbconvert
nbconvert copied to clipboard
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
The nbconvert 6.x line is not compatible with mistune >=2. Please upgrade to nbconvert 7.x.
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'
same as albe-jj
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`
As we said we are using nbconvert==7.0.0
and mistune==2.0.4
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.
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?
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
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.
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 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.
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.
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.
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
https://stackoverflow.com/a/76189658/13086128
The 7.x line imports
BlockParser
, notBlockGrammar
.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