【问题标题】:Plotly in python: Exporting to .eps - poppler library not found on path using windows在 python 中绘图:导出到 .eps - 在使用 Windows 的路径上找不到 poppler 库
【发布时间】:2022-07-26 02:50:35
【问题描述】:

我一直在使用 plotly 来创建图表和可视化。我正在本地机器(Windows)上的 jupyter notebooks 中工作。对于特定用例,我现在需要将这些图形保存在高分辨率 .eps 文件中。但是,我无法在我的 python anaconda 环境中工作。每当我尝试将图表保存到 eps 时,它都会引发以下错误(同时适用于所有其他格式)[问题末尾的示例代码]:

ValueError: Transform failed with error code 530: Exporting to EPS 格式需要 poppler 库提供的 pdftops 命令。请安装 poppler 并确保 pdftops 命令在 PATH 上可用(下面的完整错误消息)

现在,这似乎是我安装 poppler 库的问题,这并不是一个新问题。我尝试了其他线程(Poppler in path for pdf2imageHow to install Poppler on Windows?Unable to install Poppler on Windows using Conda)、https://chadrick-kwag.net/install-poppler-in-windows/ 的不同解决方案,包括:

当我在终端中输入pdftops -h 时,它可以无缝运行,在我看来,这表明它在路径上:

pdftops version 22.04.0
Copyright 2005-2022 The Poppler Developers - http://poppler.freedesktop.org
Copyright 1996-2011, 2022 Glyph & Cog, LLC
Usage: pdftops [options] <PDF-file> [<PS-file>]
  -f <int>                       : first page to print
  -l <int>                       : last page to print
 [...]

有人对如何让它工作有任何想法吗?否则 conda env/plotly 工作得很好。下面的示例代码和完整的错误消息。我将非常感激 - 我已经坚持了很长时间了。

Python:v 3.8, 情节:v 5.4.0, 波普勒:v 22.04.0

示例代码:

import plotly.graph_objects as go

fig = go.Figure(data=[go.Sankey(
    node = dict(
      pad = 15,
      thickness = 20,
      line = dict(color = "black", width = 0.5),
      label = ["A 1", "A 2", "A 3", "B 1", "B 2", "B 3", "C 1", "C 2", "C 3"],
      color = ["red", "yellow", "green", "red", "yellow", "green", "red", "yellow", "green"],
      # x = [0,0,0,0.3,0.3,0.3,0.6,0.6,0.6],
      # y = [0.5,0.3,0.1,0.5,0.3,0.1,0.5,0.3,0.1,],
      #groups = [[0,3,6], [1,4,7], [2,5,8]]
    ),
    link = dict(
      source = [0, 0, 0, 1, 1, 1,2,2,2, 3,3,3,4,4,4,5,5,5], # indices correspond to labels, eg A1, A2, A1, B1, ...
      target = [3, 4, 5, 3, 4, 5,3,4,5, 6,7,8,6,7,8,6,7,8],
      value =  [1, 3, 7, 2, 2, 2,2,1,22,1,0,5,0,3,3,3,2,26  ],
      color = ["red", "yellow", "green", "red", "yellow", "green", "red", "yellow", "green", "red", "yellow", "green", "red", "yellow", "green", "red", "yellow", "green"]
  ))])

fig.update_layout(font_size=10)
fig.write_image("Levels_Over_Time.eps", scale = 15)
fig.write_html("Levels_Over_Time.html")
fig.show()

完全错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_6248/3754478019.py in <module>
     25 
     26 fig.update_layout(autosize=False, width=1000, height=400,  margin=dict(l=65, r=65, b=50, t=50))
---> 27 fig.write_image("Levels_Over_Time.eps", scale = 15)
     28 fig.write_html("Levels_Over_Time.html")
     29 fig.show()

c:\Users\user\anaconda3\envs\Neuro_ML\lib\site-packages\plotly\basedatatypes.py in write_image(self, *args, **kwargs)
   3819         import plotly.io as pio
   3820 
-> 3821         return pio.write_image(self, *args, **kwargs)
   3822 
   3823     # Static helpers

c:\Users\user\anaconda3\envs\Neuro_ML\lib\site-packages\plotly\io\_kaleido.py in write_image(fig, file, format, scale, width, height, validate, engine)
    266     # -------------
    267     # Do this first so we don't create a file if image conversion fails
--> 268     img_data = to_image(
    269         fig,
    270         format=format,

c:\Users\user\anaconda3\envs\Neuro_ML\lib\site-packages\plotly\io\_kaleido.py in to_image(fig, format, width, height, scale, validate, engine)
    143     # ---------------
    144     fig_dict = validate_coerce_fig_to_dict(fig, validate)
--> 145     img_bytes = scope.transform(
    146         fig_dict, format=format, width=width, height=height, scale=scale
    147     )

c:\Users\user\anaconda3\envs\Neuro_ML\lib\site-packages\kaleido\scopes\plotly.py in transform(self, figure, format, width, height, scale)
    159         if code != 0:
    160             message = response.get("message", None)
--> 161             raise ValueError(
    162                 "Transform failed with error code {code}: {message}".format(
    163                     code=code, message=message

ValueError: Transform failed with error code 530: Exporting to EPS format requires the pdftops command which is provided by the poppler library. Please install poppler and make sure the pdftops command is available on the PATH

【问题讨论】:

    标签: python-3.x plotly plotly-python poppler


    【解决方案1】:

    这在 WSL2 Ubuntu 20.04 上为我解决了这个问题(本机 poppler-utils 不会)。由于这是 conda,我认为它也应该适用于您。

    conda install -c conda-forge poppler
    

    来自here

    【讨论】:

      猜你喜欢
      • 2018-08-14
      • 2017-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 2015-11-01
      相关资源
      最近更新 更多