简体   繁体   English

无法使用 Kaleido 将 plotly 图像导出为 png

[英]Unable to export plotly images to png with Kaleido

I have never used plotly before, and I have been trying to export a sample image code to png.之前没用过plotly,一直在尝试导出一个sample image code to png。 I have installed plotly and kaleido and ran the code on python 3, but nothing happens.我已经安装了 plotly 和 kaleido 并在 python 3 上运行代码,但没有任何反应。

#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.根据 plotly 文档,这应该可以解决问题,但我无法获得 png 图像。 It shows no errors, no warnings... it's like python is stuck in an infinite loop.它没有显示错误,没有警告......就像 python 陷入了无限循环。 I can't even stop the terminal from running.我什至无法阻止终端运行。

I'm using python 3.9.6 64-bit我正在使用 python 3.9.6 64 位
I have tried plotly latest version (5.3.1) and an older version (4.14.3), but I've got the same problem.我试过 plotly 最新版本(5.3.1)和旧版本(4.14.3),但我遇到了同样的问题。
python -m pip install plotly

kaleido is the latest version (0.2.1), but I have tried version (0.2.0) too. kaleido 是最新版本(0.2.1),但我也尝试过版本(0.2.0)。
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?知道为什么第一台计算机不运行代码吗?

I had the same issue.我遇到过同样的问题。 tried everything.尝试了一切。 nothing worked.没有任何效果。 then finally installed orca.然后终于安装了orca。 and.., It worked.!!和..,它的工作.!! I would suggest installing Orca for static image write when using Plotly, if nothing works.如果没有任何效果,我建议在使用 Plotly 时为 static 图像写入安装 Orca。

fig.write_image('fig1.png', engine='orca') fig.write_image('fig1.png', engine='orca')

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)我们都有 Windows Enterprise 10,相同版本相同的更新,...(由软件中心分发)
  • 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)我们有相同的 Python 环境(相同的 conda env,由软件中心分发给所有数据科学家,用户无权访问此目录进行更新)
  • We run the exact same test code from an Anaconda prompt in the same conda env我们在相同的 conda 环境中从 Anaconda 提示运行完全相同的测试代码
  • We cannot simply downgrade the version of kaleido because of this type of distribution我们不能因为这种分布就简单的降级kaleido的版本
  • For both, it works with ORCA (so it is kaleido posing the problem)对于两者,它与 ORCA 一起工作(所以它是 kaleido 提出的问题)

The only difference so far I can spot, is our machine itself.到目前为止我能发现的唯一区别是我们的机器本身。 I run on an Intel, he runs on an AMD processor.我在 Intel 上运行,他在 AMD 处理器上运行。

Well, there's actually a second.好吧,实际上还有一秒钟。 I run my Windows in English, he in Dutch.我用英语运行我的 Windows,他用荷兰语运行。

The people above who don't have this working with 1.2, it could be a suggestion to check your processor.上面没有使用 1.2 的人,建议检查你的处理器。 On my Intel it works, on his AMD it doesn't.在我的 Intel 上可以,在他的 AMD 上不行。

And, for those that don't have it working: are you running on Windows in English version?而且,对于那些没有工作的人:你在英文版的 Windows 上运行吗?

Provided you have the kaleido installed, you should specify the engine as kaleido in the object write_image .如果您安装了kaleido ,您应该在对象write_image中将engine指定为kaleido

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:结果图像: 图片

Resultant path of image saved:保存图像的结果路径: image_saved_to_path

I run Windows 10 Enterprise and this worked for me:我运行 Windows 10 企业版,这对我有用:

Downgrade Kaleido to version 0.1.0post1 (which is the latest in 0.1.*):将 Kaleido 降级到 0.1.0post1 版本(这是 0.1.* 中的最新版本):

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

Then image creation started working.然后图像创建开始工作。 Also see:另见:

https://stackoverflow.com/a/71621135/660259 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 kaleido v0.2.1 在 Windows Server 2019 上运行良好,但在我的工作计算机 Windows 10 Enterprise 上运行良好

I had the same problem.我有同样的问题。

Following the discussion here https://github.com/plotly/Kaleido/issues/36 I disabled mathjax按照这里的讨论https://github.com/plotly/Kaleido/issues/36我禁用了 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.显然这应该从 plotly v. 5 开始修复,但事实并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM