vectorbt icon indicating copy to clipboard operation
vectorbt copied to clipboard

AttributeError: type object 'DOMWidget' has no attribute '_ipython_display_'

Open shaktisd opened this issue 2 years ago • 6 comments

I am running this in jupyter lab and getting following error

import vectorbt as vbt
import yfinance
cols = ['Open', 'High', 'Low', 'Close', 'Volume']
ohlcv = vbt.YFData.download("BTC-USD").get(cols)
ohlcv.vbt.ohlcv.plot()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~\.conda\envs\vectorbacktest_env\lib\site-packages\IPython\core\formatters.py:921, in IPythonDisplayFormatter.__call__(self, obj)
    919 method = get_real_method(obj, self.print_method)
    920 if method is not None:
--> 921     method()
    922     return True

File ~\.conda\envs\vectorbacktest_env\lib\site-packages\plotly\basewidget.py:741, in BaseFigureWidget._ipython_display_(self)
    737 """
    738 Handle rich display of figures in ipython contexts
    739 """
    740 # Override BaseFigure's display to make sure we display the widget version
--> 741 widgets.DOMWidget._ipython_display_(self)

AttributeError: type object 'DOMWidget' has no attribute '_ipython_display_'

shaktisd avatar Aug 23 '22 16:08 shaktisd

@shaktisd pip install "jupyterlab>=3" "ipywidgets>=7.6", then pip install plotly==5.10.0, then run JupyterLab again.

polakowo avatar Aug 23 '22 16:08 polakowo

@polakowo - Thanks this seems to work , as I can see the graph but the error still comes . Is there a way to remove that also ?

image

shaktisd avatar Aug 23 '22 16:08 shaktisd

I was having exactly this problem in Jupyter notebook. In case it helps someone else, the workaround that eliminated the problem for me, after following the plotly recommendation

$ pip install "notebook>=5.3" "ipywidgets>=7.5"

was by downgrading these packages:

pip install ipywidgets==7.7.1 and jupyterlab-widgets==1.1.1

as per this answer https://github.com/plotly/plotly.py/issues/3686#issuecomment-1220658377. Probably it's the ipywidgets downgrade that fixes it. I know I was previously on ipywidgets>=8.0.0, not sure of the previous jupyterlab-widgets version.

puppriss avatar Sep 05 '22 06:09 puppriss

@polakowo - Thanks this seems to work , as I can see the graph but the error still comes . Is there a way to remove that also ?

image

You can use ohlcv.vbt.ohlcv.plot().show(), by adding show method, it will remove the error message. It worked for me.

john-2424 avatar Sep 10 '22 00:09 john-2424

Downgraded to ipywidgets==7.7.1 to workaround this issue.

guhuajun avatar Sep 19 '22 03:09 guhuajun

Can confirm ipywidgets==7.7.2 works too.

yarbs avatar Oct 27 '22 02:10 yarbs