0

I am following a tutorials in plotly official website. I am using jupyter notebook. and I got an import error for plot.grid_objs. I am using plotly 4.0. Any suggestion to fix it? Thanks

https://plotly.com/python/v3/gapminder-example/

ImportError: The plotly.grid_objs module is deprecated, please install the chart-studio package and use the chart_studio.grid_objs module instead


import plotly as py
import plotly.figure_factory as FF
from plotly.grid_objs import Grid, Column

import pandas as pd
import time
import pickle

filename_pickle='dataset.pkl'
try:
    dataset=pd.read_pickle(filename_pickle)
except FileNotFoundError: 
    url = 'https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv'
    dataset = pd.read_csv(url)
    dataset.to_pickle(filename_pickle)

table = FF.create_table(dataset.head(10))
py.offline.iplot(table)  # table is inline inside jupyter notebook

ImportError: 
The plotly.grid_objs module is deprecated,
please install the chart-studio package and use the
chart_studio.grid_objs module instead

2 Answers 2

2

Looks like the tutorial is for a much older version of plotly. Try:

pip install plotly==2.0.1

in your terminal and then rerun the Python code.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Frodnar. I have plotly 4 installed. are you suggesting me to downgrad from version 4 to version 2? If I install plotly 2, will there be a conflict in the future? Thanks
Quite possibly, There are a couple of ways to handle that. Most recommended is to learn to use virtual environments which allow you to install and isolate different package versions for different tasks. This is an important part of working with Python anyway, so you may as well ross that bridge now. Otherwise, you could try to upgrade to plotly v4 after you're done with whatever you're working on at the moment and just write yourself a commented note at the top of this project reminding you to downgrade should you come back to it later.
@Frodnar, although downgrading is a useful skill and an overall important part of working with python, it is not necessary in this case.
2

By referencing the documentation, you can find that do something as seen here:

import chart_studio
from chart_studio.grid_objs import Column, Grid

It also says to Replace plotly.grid_objs with chart_studio.grid_objs in the version 4 migration guide. In this case, a version downgrade is not necessary.

3 Comments

Thanks as11, I appreicate your help me today for few times. Not sure why it still doesn't work, AttributeError: module 'chart_studio' has no attribute 'grid_ops
I have seen some people pip uninstall chart_studio then pip install chart_studio, maybe also try pip3 install chart_studio
Another thing you could also potentially try is from chart_studio import grid_objs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.