Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Possible Windows-only error on save() to PNG #121

Closed
asarmy opened this issue Jul 7, 2020 · 19 comments
Closed

Possible Windows-only error on save() to PNG #121

asarmy opened this issue Jul 7, 2020 · 19 comments
Labels
bug Something isn't working

Comments

@asarmy
Copy link

asarmy commented Jul 7, 2020

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.
image

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'
@jakevdp
Copy link
Member

jakevdp commented Jul 7, 2020

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!

@jakevdp jakevdp added the bug Something isn't working label Jul 7, 2020
@stanmart
Copy link

stanmart commented Jul 8, 2020

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 #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.

@amine-aboufirass
Copy link

Is there a workaround to this?

@jakevdp
Copy link
Member

jakevdp commented Aug 14, 2020

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?

@nickcorona
Copy link

nickcorona commented Sep 16, 2020

MAN! I have this same issue.

@Amarounek
Copy link

Amarounek commented Oct 3, 2020

Same issue with svg format. :-(

@balrog-nona
Copy link

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.

@jakevdp
Copy link
Member

jakevdp commented Nov 5, 2020

@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

@balrog-nona
Copy link

@jakevdp Thank you for the link. Looks like I'll have to configure geckodriver.

@dkruszew
Copy link

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.

@Jtuppack
Copy link

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?

@thefabnab
Copy link

I'm seeing the same issue right now as well. Temperamental would be the way I'd characterize it as well.

@jhermann
Copy link

FYI, I solved this on Win10 / WSL1 by .venv/bin/npm install vega-lite vega-cli canvas into a mixed Python/Node virtualenv.

@hoctro01
Copy link

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

@joelostblom
Copy link
Member

@hoctro01 Try following the troubleshooting steps in the altair-saver installation instructions https://github.com/altair-viz/altair_saver/#installation

@hoctro01
Copy link

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

@jhermann
Copy link

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.

@joelostblom joelostblom transferred this issue from vega/altair Sep 21, 2023
@joelostblom
Copy link
Member

I moved this issue into the altair-saver repo since altair now mainly recommends using vl-convert for saving static chart images.

@joelostblom
Copy link
Member

Since Altair 5.2, the functionality of Altair Saver is now available in Altair via the vl-convert package. Most of the functionality has been available since 5.0, and the main addition in 5.2 was PDF export. See the docs on how to save charts for more details

We are going to archive this repo, so I'm closing all the open issues and PRs before doing so. Try out the new options for saving charts mentioned above and if you run into issues, please open an issue directly in the altair or vl-convert repo.

@joelostblom joelostblom closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests