Saving a plotly image not working with kaleido even though it is installed
Asked Answered
T

5

10

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?

Twelvemonth answered 14/2, 2022 at 21:39 Comment(8)
What happens if you insert the line import kaleido; print(kaleido.__version__) before fig.write_image(path)`Casta
@DerekO I get 0.2.1Twelvemonth
are you working in a virtual environment? Do you get the same error if you run your code in terminal?Casta
I can't run that in the terminal. What command should I run @DerekOTwelvemonth
in terminal, what if you try fig=go.Figure() and then fig.write_image('test.png') ?Casta
I get an error. Are you sure you don't mean the console?Twelvemonth
Did you ever figure this out? Having same issue.Pancho
@Pancho unfortunately not, I just moved on without.Twelvemonth
E
8

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')
Eweneck answered 10/5, 2022 at 20:13 Comment(0)
S
1

The transition from Orca to Kaleido is not without speed bumps.

For users on Windows 10 and 11, users seem to have luck rolling back to Kaleido version 0.1.0, see. https://github.com/plotly/Kaleido/issues/110

Stallfeed answered 20/6, 2022 at 10:24 Comment(0)
S
1

Got this exact issue on colab and tried all options but didn't work. Then, found out that if you revert Plotly to version 5.3.1, the issue goes away. Not the best fix, but was the only thing that worked for me.

!pip uninstall ploty !pip install plotly==5.3.1 import plotly import kaleido

Stative answered 31/5, 2023 at 20:0 Comment(0)
P
0

I ran into a similar problem on Windows 10. It turned out to solve the problem by changing the rendering method

set KALIDO_USE_SWIFT=true
Pericardium answered 21/8, 2024 at 19:31 Comment(0)
H
-1

I got the same problem in a Jupyter Notebook and got it to work by restarting the kernel and then specifying one more argument: engine="kaleido". Your mileage may vary...

import kaleido
import plotly.io as pio

pio.write_image(my_file, 'path/to/my/directory/file.svg', engine="kaleido")
Hyacinthus answered 1/2, 2024 at 2:5 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.