-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kaleido fails to save image with fig.write_image() #170
Comments
Same issue here on Linux: I create a virtual env with conda: conda create -n "tmpenv_py12" python=3.12 jupyter ipykernel numpy plotly python-kaleido And when I execute the following code in a notebook: import numpy as np
import plotly.graph_objects as go
import plotly, ipykernel, kaleido
print(f"plotly: {plotly.__version__}")
print(f"kaleido: {kaleido.__version__}")
print(f"ipykernel: {ipykernel.__version__}")
n = 20000
x = np.arange(n)
noisy_sine = (3 + np.sin(x / 2000) + np.random.randn(n) / 10) * x / (n / 4)
fig = go.Figure()
fig.add_traces(
[
{"y": noisy_sine + 2, "name": "yp2", "type": "scattergl"},
{"y": noisy_sine - 3, "name": "ym1", "type": "scatter"},
]
)
fig.write_image("tmp.png") Then I have the following error: ---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[2], line 23
16 fig = go.Figure()
17 fig.add_traces(
18 [
19 {"y": noisy_sine + 2, "name": "yp2", "type": "scattergl"},
20 {"y": noisy_sine - 3, "name": "ym1", "type": "scatter"},
21 ]
22 )
---> 23 fig.write_image("tmp.png")
File ~/miniconda3/envs/tmpenv_py12/lib/python3.12/site-packages/plotly/basedatatypes.py:3829, in BaseFigure.write_image(self, *args, **kwargs)
3769 """
3770 Convert a figure to a static image and write it to a file or writeable
3771 object
(...)
3825 None
3826 """
3827 import plotly.io as pio
-> 3829 return pio.write_image(self, *args, **kwargs)
File ~/miniconda3/envs/tmpenv_py12/lib/python3.12/site-packages/plotly/io/_kaleido.py:267, in write_image(fig, file, format, scale, width, height, validate, engine)
251 raise ValueError(
252 """
253 Cannot infer image type from output path '{file}'.
(...)
261 )
262 )
264 # Request image
265 # -------------
266 # Do this first so we don't create a file if image conversion fails
--> 267 img_data = to_image(
268 fig,
269 format=format,
270 scale=scale,
271 width=width,
272 height=height,
273 validate=validate,
274 engine=engine,
275 )
277 # Open file
278 # ---------
279 if path is None:
280 # We previously failed to make sense of `file` as a pathlib object.
281 # Attempt to write to `file` as an open file descriptor.
File ~/miniconda3/envs/tmpenv_py12/lib/python3.12/site-packages/plotly/io/_kaleido.py:144, in to_image(fig, format, width, height, scale, validate, engine)
141 # Validate figure
142 # ---------------
143 fig_dict = validate_coerce_fig_to_dict(fig, validate)
--> 144 img_bytes = scope.transform(
145 fig_dict, format=format, width=width, height=height, scale=scale
146 )
148 return img_bytes
File ~/miniconda3/envs/tmpenv_py12/lib/python3.12/site-packages/kaleido/scopes/plotly.py:153, in PlotlyScope.transform(self, figure, format, width, height, scale)
142 raise ValueError(
143 "Invalid format '{original_format}'.\n"
144 " Supported formats: {supported_formats_str}"
(...)
148 )
149 )
151 # Transform in using _perform_transform rather than superclass so we can access the full
152 # response dict, including error codes.
--> 153 response = self._perform_transform(
154 figure, format=format, width=width, height=height, scale=scale
155 )
157 # Check for export error, later can customize error messages for plotly Python users
158 code = response.get("code", 0)
File ~/miniconda3/envs/tmpenv_py12/lib/python3.12/site-packages/kaleido/scopes/base.py:293, in BaseScope._perform_transform(self, data, **kwargs)
284 """
285 Transform input data using the current scope, returning dict response with error code
286 whether successful or not.
(...)
290 :return: Dict of response from Kaleido executable, whether successful or not
291 """
292 # Ensure that kaleido subprocess is running
--> 293 self._ensure_kaleido()
295 # Perform export
296 export_spec = self._json_dumps(dict(kwargs, data=data)).encode('utf-8')
File ~/miniconda3/envs/tmpenv_py12/lib/python3.12/site-packages/kaleido/scopes/base.py:198, in BaseScope._ensure_kaleido(self)
193 if not startup_response_string:
194 message = (
195 "Failed to start Kaleido subprocess. Error stream:\n\n" +
196 self._get_decoded_std_error()
197 )
--> 198 raise ValueError(message)
199 else:
200 startup_response = json.loads(startup_response_string)
ValueError: Failed to start Kaleido subprocess. Error stream:
[0314/110840.788795:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale
[0314/110840.793322:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale
[0314/110840.793323:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale
Received signal 7 BUS_ADRERR 7feace9a6000
#0 0x55967f7aad79 base::debug::CollectStackTrace()
#1 0x55967f728633 base::debug::StackTrace::StackTrace()
#2 0x55967f7aa95b base::debug::(anonymous namespace)::StackDumpSignalHandler()
#3 0x7fead1e54520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x4251f)
#4 0x55967d914f47 FT_Stream_ReadULong
#5 0x55967d94621b sfnt_open_font
#6 0x55967d941990 sfnt_init_face
#7 0x55967d950079 tt_face_init
#8 0x55967d915bbb open_face
#9 0x55967d910b23 ft_open_face_internal
#10 0x55967d910950 FT_New_Face
#11 0x55967fd5659c IA__FcFreeTypeQueryAll
#12 0x55967fd5367d FcFileScanConfig
#13 0x55967fd539b6 FcDirScanConfig
#14 0x55967fd53afa FcDirCacheScan
#15 0x55967fd53bae IA__FcDirCacheRead
#16 0x55967fd4a027 FcConfigAddDirList
#17 0x55967fd49f67 FcConfigBuildFonts
#18 0x55967fd57c81 IA__FcInitLoadConfigAndFonts
#19 0x55967fd49422 FcConfigInit
#20 0x559680052287 gfx::GetGlobalFontConfig()
#21 0x55967e1406f5 content::BrowserMainRunnerImpl::Initialize()
#22 0x559680c127b7 headless::HeadlessContentMainDelegate::RunProcess()
#23 0x55967f491f3e content::ContentMainRunnerImpl::RunServiceManager()
#24 0x55967f491b76 content::ContentMainRunnerImpl::Run()
#25 0x55967f48f374 content::RunContentProcess()
#26 0x55967f48fcfc content::ContentMain()
#27 0x55967f4e1182 headless::(anonymous namespace)::RunContentMain()
#28 0x55967f4e1025 headless::HeadlessBrowserMain()
#29 0x55967d4fffa8 main
#30 0x7fead1e3bd90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
#31 0x7fead1e3be40 __libc_start_main
#32 0x55967d4f93ea _start
r8: 0000000000000000 r9: 0000000000000000 r10: 0000000000000002 r11: 0000000000000293
r12: 000024a917438800 r13: 0000000000000000 r14: 00007ffcca38ddc4 r15: 00007feace9a6000
di: 000024a9174d0280 si: 0000000000000000 bp: 00007ffcca38dbc0 bx: 000024a9174d0280
dx: 00007ffcca38dea8 ax: 0000000000000000 cx: 00007ffcca38de68 sp: 00007ffcca38dba0
ip: 000055967d914f47 efl: 0000000000010206 cgf: 002b000000000033 erf: 0000000000000004
trp: 000000000000000e msk: 0000000000000000 cr2: 00007feace9a6000
[end of stack trace]
Calling _exit(1). Core file will not be generated. Do you have any idea where it might come from ? |
Fixed by reverting to version pip install "kaleido==0.1.0.post1" |
I've only changed my connexion from WIFI to regular wire and then fig.write_image() worked again. I don't know if it is the reason why, but for sure I did'nt change my environnement neither my kaleido version (still 0.2.1) |
Thanks for your interest in Kaleido. We are currently working on an overhaul that might address your issue - we hope to have news in a few weeks and will post an update then. Thanks - @gvwilson |
Hi,
My issue looks like the #148, but it is more general.
While working perfectly 2 months ago, kaleido did not work anymore for graph export.
In the following exemple, my fig is well plotted, the html is well generated, but the third ligne is not working (no message error, but a endless computation).
fig.show()
fig.write_html(os.path.join(folder_out, dataset_name + '_graph_monthly.html'))
fig.write_image(monthly_graph_file)
If I interrupt the kernel, I have the following error
What is surprising is that the function worked earlier (month ago) with the same environnment.
What is more surprising is that, today, it worked once, but then it doesn't work anymore. Seems randomly.
Today, I had my firewall (Windows defender ) automaticaly updated on my pro computer, but I don't know if it is related.
I tried to open the generated html fig before running the write_image but that's not that
I work with
Python 3.11.5
conda version 23.7.1
python-kaleido 0.2.1 installed with conda-forge
The text was updated successfully, but these errors were encountered: