Getting Altair to work with Jupyter Notebook
Asked Answered
B

1

5

Trying to get Altair to work with Jupyter Notebook, I installed it using

conda install -c conda-forge altair vega_datasets notebook vega

But when I try to do an example plot

import altair as alt
from vega_datasets import data

# for the notebook only (not for JupyterLab) run this command once per session
alt.renderers.enable('notebook')

iris = data.iris()

alt.Chart(iris).mark_point().encode(
    x='petalLength',
    y='petalWidth',
    color='species'
)

as seen in their quick start guide, I get

ValueError: 
To use the 'notebook' renderer, you must install the vega package
and the associated Jupyter extension.
See https://altair-viz.github.io/getting_started/installation.html
for more information.

even though I have installed vega using Conda. I can make vega example plots though. I am unable to enable the Jupyter extension though, as Jupyter says it is incompatible.

Any help is appreciated.

Befriend answered 25/8, 2018 at 23:49 Comment(0)
C
11

For the current release of altair (Version 2.2), use

conda install -c conda-forge vega=1.3

or

pip install vega==1.3

and then restart the notebook.

The vega python extension was mistakenly updated this week to only support vega-lite 3.0, which is not yet released and thus not yet supported by Altair.

See https://github.com/altair-viz/altair/issues/1114 for the initial bug report.

Cammie answered 26/8, 2018 at 19:20 Comment(3)
Yep. Thanks a lot for this. For the record, the conda version of this didn't work (but the pip did).Befriend
Thanks – you need to specify the conda-forge channel if it's not in your defaults, as you did in your question. I've edited the answer to be more clear on this.Cammie
Same here, conda install -c conda-forge vega & conda install -c conda-forge vega=1.3 did not work for me (stuck on solving environment for >12 hours; I tried conda config --set channel_priority strict as suggested at github.com/conda/conda/issues/8197 but still no luck). However, pip install vega did work instantly. Using Windows 10, Python 3.7.6, Conda 4.6.14.Indifference

© 2022 - 2024 — McMap. All rights reserved.