'Saving a plotly image not working with kaleido even though it is installed

I am trying to save a simple plotly figure to a directory. I understand it needs kaleido (I have version '0.2.1') and also at least plotly '5.3.1' which are installed.

However trying to save the image I get the following error:

fig.write_image(path)

ValueError: 
Image export using the "kaleido" engine requires the kaleido package,
which can be installed using pip:
$ pip install -U kaleido

Why is this occuring when all the required packages are there?



Solution 1:[1]

I've got exactly the same issue on google colab. Even after installation kaleido, the same error. Accidentally I've found fix, it seems necesarry to import kaleido first:

!pip install kaleido
import kaleido #required
kaleido.__version__ #0.2.1

import plotly
plotly.__version__ #5.5.0

#now this works:
import plotly.graph_objects as go

fig = go.Figure()
fig.write_image('aaa.png')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Quant Christo