Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed

I was trying to print a plotly plot in Visual Studio Code and caught this error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-40-e07b5feb5ded> in <module>
     30 
     31 fig.update_layout(height=nrows*500)
---> 32 fig.show()

C:\Python38\lib\site-packages\plotly\basedatatypes.py in show(self, *args, **kwargs)
   3147         import plotly.io as pio
   3148 
-> 3149         return pio.show(self, *args, **kwargs)
   3150 
   3151     def to_json(self, *args, **kwargs):

C:\Python38\lib\site-packages\plotly\io\_renderers.py in show(fig, renderer, validate, **kwargs)
    383 
    384         if not nbformat or LooseVersion(nbformat.__version__) < LooseVersion("4.2.0"):
--> 385             raise ValueError(
    386                 "Mime type rendering requires nbformat>=4.2.0 but it is not installed"
    387             )

ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed

The code I used:


import plotly.graph_objects as go
from plotly.subplots import make_subplots
import plotly.express as px

df = df[df['Data']>0]
df['Timestamp'] = pd.to_datetime(df['Timestamp'])
df = df[(df['Id'] ==1)|(df['Id'] ==6)]

dfp = pd.pivot_table(df,
                     values='Data',
                     index=['Timestamp'],
                     columns=['Id'],
               )
nrows = len(dfp.columns) 

fig = make_subplots(rows=nrows,
                    cols=1,
                    subplot_titles=['Id '+str(c) for c in dfp.columns])

# add traces
x = 1
for i, col in enumerate(dfp.columns):
    fig.add_trace(go.Scatter(x=dfp.index, y=dfp[col].values,
                             name = 'Id '+str(col),
                             mode = 'lines',
                             ),
                  row=i+1,
                  col=1)

fig.update_layout(height=nrows*500)
fig.show()

I tried pip install nbformat in the console following this feed on GitHub and this question on stackoverflow but it did not work.

However, it seems the code could run with the last 2 rows removed:

fig.update_layout(height=nrows*500)
fig.show()
like image 834
nilsinelabore Avatar asked Mar 10 '21 02:03

nilsinelabore


People also ask

What is the nbformat required for MIME type rendering?

ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed Ask Question Asked9 months ago Active1 month ago Viewed15k times 18

Do I need to install nbformat in kernel?

When you have several kernels you can access from jupyter-lab/notebook you need to install nbformat within the kernel in order to have plotly works. In the previous version it wasn't necessary. Sorry, something went wrong. any updates? Sorry, something went wrong. any updates? Not that I know.

Is nbformat required for Plotly to work?

Apparently nbformat is required by the latest plotly version. After a clean install if I try to plot I receive back this error If you want I can update the requirements that I guess are here. Hi @rpanai thank you for the report.

Is nbformat needed to display figures in notebook?

On top of the requirements listed in requirements.txt, we also have some optional requirements which are not installed by defaults. nbformat is indeed needed to display figures in the notebook.


3 Answers

Method 1.

reinstall ipykernel via pipenv install ipykernel

Method 2.

pip install --upgrade nbformat
like image 109
J00N Avatar answered Oct 07 '22 04:10

J00N


!pip install nbformat 
  1. Install this.
  2. Restart your Kernel.
  3. Dam sure it will work!
like image 30
Aravind R Avatar answered Oct 07 '22 04:10

Aravind R


For those that use conda, this worked for me:

Verify the name of your conda environment: conda info --envs

Supposing it's "myenv", proceed:

conda activate myenv
conda install nbformat

Then restart the kernel.

like image 4
Matt Payne Avatar answered Oct 07 '22 03:10

Matt Payne