altair
altair copied to clipboard
Possible Windows-only error on save() to PNG
Getting an error using Altair saver when I am trying to save a chart to a PNG in Jupyter Notebook: ValueError: Unsupported format: 'png'
Answer here on Stack Overflow suggested filing a bug report.

System info:
Windows 10 conda 4.8.2 Python 3.8.3 altair 4.1.0 py_1 conda-forge altair_saver 0.1.0 py_0 conda-forge vega 3.4.0 py38h32f6830_0 conda-forge selenium 3.141.0 py38h9de7a3e_1001 conda-forge
Example Code:
import pandas as pd
import altair as alt
from altair_saver import save
alt.renderers.enable('default'); # if in jupyter, ; to suppress output
alt.renderers.enable('altair_saver', fmts=['vega-lite', 'png']);
mytaskbars = pd.DataFrame([
{"task": "Task1a", "start": '2020-06-01', "end": '2020-09-30', "color": 'royalblue'},
{"task": "Task1b", "start": '2020-06-01', "end": '2021-03-31', "color": 'deepskyblue'},
{"task": "Task2", "start": '2020-06-01', "end": '2021-03-31', "color": 'red'},
])
mytaskbars["start"] = pd.to_datetime(mytaskbars["start"])
mytaskbars["end"] = pd.to_datetime(mytaskbars["end"])
chart = alt.Chart(mytaskbars).mark_bar(opacity=0.7).encode(
x=alt.X('start', axis=alt.Axis(title='Date', labelAngle=-45, format = ("%b %Y"))),
x2 = 'end',
y=alt.Y('task', axis=alt.Axis(title=None)),
color = alt.Color('color:N', scale = None)
)
save(chart, "chart_202006.png")
chart
Error Message:
ValueError Traceback (most recent call last)
<ipython-input-3-13a284c2aca9> in <module>
19 )
20
---> 21 save(chart, "chart_202006.png")
22 chart
~\anaconda3\envs\geospat_env\lib\site-packages\altair_saver\_core.py in save(chart, fp, fmt, mode, method, **kwargs)
60 """
61 if method is None:
---> 62 Saver = _get_saver_for_format(fmt=fmt, fp=fp)
63 elif isinstance(method, type):
64 Saver = method
~\anaconda3\envs\geospat_env\lib\site-packages\altair_saver\_core.py in _get_saver_for_format(fmt, fp)
28 if fmt in s.valid_formats and s.enabled():
29 return s
---> 30 raise ValueError(f"Unsupported format: {fmt!r}")
31
32
ValueError: Unsupported format: 'png'
Thanks – I don't have a windows machine to debug this, so if you're able to figure out the issue and submit a fix, that would be very helpful!
Can confirm it on my system as well. It looks to be an issue with altair_saver, not Altair itself. Also, most likely related to https://github.com/altair-viz/altair_saver/issues/70 It is supposedly fixed in the newer versions of altair_saver, but due to their dependence on vega-cli and vega-lite-cli they cannot be installed on Windows.
Is there a workaround to this?
I don't know of any workaround. I don't have access to a Windows machine to try it out. Perhaps someone who has access to a windows machine might volunteer to work on it?
MAN! I have this same issue.
Same issue with svg format. :-(
I have the same issue after upgradig from Fedora 31 to Fedora 32. It worked perfectly with Fedora 31, but with Fedora 32, the code
import altair as alt
base = alt.Chart(data_df).properties(width=500) # creating Chart object
line = base.mark_line(color='crimson').encode(x='date', y='kms') # data visualization using Line Chart
rule = base.mark_rule(color='coral').encode(y='average(kms)', size=alt.value(2)) # line for average kms
my_chart = line + rule
my_chart.save('chart.png')
goes with this error:
Traceback (most recent call last):
File "main.py", line 130, in <module>
my_chart.save('chart.png')
File "/home/balrog/.local/lib/python3.8/site-packages/altair/vegalite/v4/api.py", line 476, in save
result = save(**kwds)
File "/home/balrog/.local/lib/python3.8/site-packages/altair/utils/save.py", line 112, in save
mimebundle = spec_to_mimebundle(
File "/home/balrog/.local/lib/python3.8/site-packages/altair/utils/mimebundle.py", line 60, in spec_to_mimebundle
return altair_saver.render(spec, format, mode=mode, **kwargs)
File "/home/balrog/.local/lib/python3.8/site-packages/altair_saver/_core.py", line 255, in render
Saver = _select_saver(method, mode=mode, fmt=fmt)
File "/home/balrog/.local/lib/python3.8/site-packages/altair_saver/_core.py", line 69, in _select_saver
raise ValueError(f"No enabled saver found that supports format={fmt!r}")
ValueError: No enabled saver found that supports format='png'
Thanks for any suggestions how to fix it.
@balrog-nona This is unrealted to the windows error in this issue. You need to install additional requirements in order to save to PNG; see the installation instructions here: https://github.com/altair-viz/altair_saver#additional-requirements
@jakevdp Thank you for the link. Looks like I'll have to configure geckodriver.
I encountered the same issue while running the altair_saver.save() function on my Windows 10 machine: i.e this error: No enabled saver found that supports format='png'.
Investigating the error led me to the below code within _core.py in the altair_saver package, which indicated that the error statement I was receiving was likely due to the below if statement failing for each saver method:
for s in _SAVER_METHODS.values():
if s.enabled() and fmt in s.valid_formats[mode]:
return s
raise ValueError(f"No enabled saver found that supports format={fmt!r}")
I originally thought that the above if statements were failing because of the file format png in s.valid_formats[mode]. Upon investigation I discovered the png string was fine, and the issue appeared to exist within s.enabled(). I did some further digging where I played with the method and webdriver arguments in the save function. When respectively using method=selenium with webdriver=chrome I received an error that told me my chromedriver.exe file was out of date for my chrome browser. I re-downloaded from here and replaced the file in C:\Windows. After doing so the save function worked seamlessly.
I find the error No enabled saver found that supports format='png' to be very temperamental. Previously I had it working and successfully outputting to a .png but since opening a new instance of my Jupyter notebook I'm getting the error again.
@dkruszew would it be possible to share more of your code, namely the save function?
I'm seeing the same issue right now as well. Temperamental would be the way I'd characterize it as well.
FYI, I solved this on Win10 / WSL1 by .venv/bin/npm install vega-lite vega-cli canvas into a mixed Python/Node virtualenv.
Hi, i used atlair_save debug with PyCharm working fine. But i run code with service on ubuntu then error "No enabled saver found that supports format='png'" Can you help me!
ubuntu 20.04 python 3.8.10 altair-4.1.0 altair_saver-0.5.0
@hoctro01 Try following the troubleshooting steps in the altair-saver installation instructions https://github.com/altair-viz/altair_saver/#installation
I have installed and run code with terminal or pycharm on ubuntu ok, but i puslish systemd service ubuntu not working ("No enabled saver found that supports format='png'")
[Unit] Description=TestBotService After=network.target [Service] Type=simple User=root ExecStart=/home/vtn-bot/miniconda3/envs/ipkv_bot/bin/python /home/vtn-bot/ipkv_bot/bot_test.py Restart=always RestartSec=3 [Install] WantedBy=multi-user.target
You need to find out the difference in your shell env vs. the systemd one -- starting with the fact you run this as root. If you try the ExecStart command in a root shell that might enlighten you as to a cause.
Or look into systemd user services and run as vtn-bot.