7

I have never used plotly before, and I have been trying to export a sample image code to png. I have installed plotly and kaleido and ran the code on python 3, but nothing happens.

#Here is the code:

import plotly.express as px
import numpy as np
    
# RGB Data as numpy array
img_rgb = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]],], dtype=np.uint8)
  
fig = px.imshow(img_rgb)
fig.show()

fig.write_image("fig.png")

According to the plotly documentation, that should do the trick, but I can't get a png image. It shows no errors, no warnings... it's like python is stuck in an infinite loop. I can't even stop the terminal from running.

I'm using python 3.9.6 64-bit
I have tried plotly latest version (5.3.1) and an older version (4.14.3), but I've got the same problem.
python -m pip install plotly

kaleido is the latest version (0.2.1), but I have tried version (0.2.0) too.
python -m pip install -U kaleido

What could I be doing wrong?

UPDATE: I have tried the same process in another computer, and it worked ok. Any ideas why the first computer won't run the code?

kenlukas
  • 3,616
  • 9
  • 25
  • 36
Karol Duarte
  • 123
  • 1
  • 1
  • 8
  • 1
    I have the same problem in jupyter lab. The command hangs forever. Same thing happens if I try `fig.show(renderer = 'png')` or `fig.show(renderer = 'svg')`. If I interrupt the kernel, the trace shows it hangs on line 192 of base.py: `startup_response_string = self._proc.stdout.readline().decode('utf-8')` – the.real.gruycho Oct 14 '21 at 15:22

6 Answers6

12

I run Windows 10 Enterprise and this worked for me:

Downgrade Kaleido to version 0.1.0post1 (which is the latest in 0.1.*):

pip install --upgrade "kaleido==0.1.*"

Then image creation started working. Also see:

https://stackoverflow.com/a/71621135/660259

Funny thing? kaleido v0.2.1 works fine on windows server 2019, but not on my work-computer Windows 10 Enterprise

jonasfh
  • 4,151
  • 2
  • 21
  • 37
  • 1
    Thanks, this worked for my windows 10 machine :) – GarethD Jul 22 '22 at 13:03
  • 1
    This worked for me as well ! Many thanks. I had version 0.2 that used to work perfectly in a previous machine. But since migrating to my new machine, it stopped working causing the exact issue described in the question. Downgrading kaleido to 0.1 has solved the issue. – AmineBTG Aug 24 '22 at 12:37
  • 1
    For conda users: `conda install -c conda-forge python-kaleido=0.1.0` – Daniel Oct 31 '22 at 13:00
  • This just saves my day! I am on Windows 11 and it works! – Jansen Simanullang Mar 17 '23 at 09:07
  • Worked for me on Databricks. Before that I was getting `Image export using the "kaleido" engine requires the kaleido package`, even though it is installed. – Julien Massardier Apr 29 '23 at 18:41
1

I had the same issue. tried everything. nothing worked! then finally installed orca. and... It worked!!! I would suggest installing Orca for static image write when using Plotly, if nothing works.

fig.write_image('fig1.png', engine='orca')
Voodu
  • 770
  • 7
  • 18
Madi
  • 11
  • 2
0

It was --single-process that fixed it for me.

Code is:

import plotly.io as pio
                                                                         
pio.kaleido.scope.chromium_args += ("--single-process",) 
Honey Thakuria
  • 223
  • 3
  • 16
-1

Provided you have the kaleido installed, you should specify the engine as kaleido in the object write_image.

I could recreate the produce the following with the solution:

import plotly.express as px
import numpy as np

    
# RGB Data as numpy array
img_rgb = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]],], dtype=np.uint8)
  
fig = px.imshow(img_rgb)
fig.show()

fig.write_image('fig.png', engine='kaleido')

Resultant Image: image

Resultant path of image saved: image_saved_to_path

Roxy
  • 1,015
  • 7
  • 20
-1

I'm facing the same issues as above. But stranger, it works on my machine but not on the user's machine.

  • We both have Windows Enterprise 10, same version same updates, ... (distributed by Software Center)
  • We have identical Python environments (same conda env, distributed by Software Center to all the data scientists, users have no access to this directory to make updates)
  • We run the exact same test code from an Anaconda prompt in the same conda env
  • We cannot simply downgrade the version of kaleido because of this type of distribution
  • For both, it works with ORCA (so it is kaleido posing the problem)

The only difference so far I can spot, is our machine itself. I run on an Intel, he runs on an AMD processor.

Well, there's actually a second. I run my Windows in English, he in Dutch.

The people above who don't have this working with 1.2, it could be a suggestion to check your processor. On my Intel it works, on his AMD it doesn't.

And, for those that don't have it working: are you running on Windows in English version ?

vindevoy
  • 19
  • 2
  • 1
    This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/32824899) – Andrew Ryan Oct 04 '22 at 06:35
  • Sorry for trying to help, Andrew Ryan – vindevoy Aug 04 '23 at 14:39
-2

I had the same problem.

Following the discussion here https://github.com/plotly/Kaleido/issues/36 I disabled mathjax

import plotly.io as pio
pio.kaleido.scope.mathjax = None

and voila! plots started to appear.

Apparently this should be fixed from plotly v. 5 onwards, but it's not.

the.real.gruycho
  • 608
  • 3
  • 17