I've gone through the display troubleshooting and the only discrepancy I see is that I can't get jupyter labextension list to show @jupyterlab/vega3-extension, though I note the comment in the Quick Start: Altair + JupyterLab jupyter labextension install @jupyterlab/vega3-extension # not needed for JupyterLab 0.32 or newer and my version of JupyterLab is 0.32.1.
When I do the example:
import altair as alt
from vega_datasets import data
cars = data.cars()
alt.Chart(cars).mark_point().encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
)
I see:
Chart({
data: Acceleration Cylinders Displacement Horsepower Miles_per_Gallon \
0 12.0 8 307.0 130.0 18.0
1 11.5 8 350.0 165.0 15.0
2 11.0 8 318.0 150.0 18.0
3 12.0 8 304.0 150.0 16.0
4 10.5 8 302.0 140.0 17.0
5 10.0 8 429.0 198.0 15.0
6 9.0 8 454.0 220.0 14.0
7 8.5 8 440.0 215.0 14.0
8 10.0 8 455.0 225.0 14.0
9 8.5 8 390.0 190.0 15.0
10 17.5 4 133.0 115.0 NaN
11 11.5 8 350.0 165.0 NaN
12 11.0 8 351.0 153.0 NaN
13 10.5 8 383.0 175.0 NaN
14 11.0 8 360.0 175.0 NaN
15 10.0 8 383.0 170.0 15.0
16 8.0 8 340.0 160.0 14.0
17 8.0 8 302.0 140.0 NaN
18 9.5 8 400.0 150.0 15.0
19 10.0 8 455.0 225.0 14.0
20 15.0 4 113.0 95.0 24.0
21 15.5 6 198.0 95.0 22.0
22 15.5 6 199.0 97.0 18.0
23 16.0 6 200.0 85.0 21.0
24 14.5 4 97.0 88.0 27.0
25 20.5 4 97.0 46.0 26.0
26 17.5 4 110.0 87.0 25.0
27 14.5 4 107.0 90.0 24.0
28 17.5 4 104.0 95.0 25.0
29 12.5 4 121.0 113.0 26.0
.. ... ... ... ... ...
376 18.6 4 112.0 88.0 27.0
377 18.0 4 112.0 88.0 34.0
378 16.2 4 112.0 85.0 31.0
379 16.0 4 135.0 84.0 29.0
380 18.0 4 151.0 90.0 27.0
381 16.4 4 140.0 92.0 24.0
382 20.5 4 151.0 NaN 23.0
383 15.3 4 105.0 74.0 36.0
384 18.2 4 91.0 68.0 37.0
385 17.6 4 91.0 68.0 31.0
386 14.7 4 105.0 63.0 38.0
387 17.3 4 98.0 70.0 36.0
388 14.5 4 120.0 88.0 36.0
389 14.5 4 107.0 75.0 36.0
390 16.9 4 108.0 70.0 34.0
391 15.0 4 91.0 67.0 38.0
392 15.7 4 91.0 67.0 32.0
393 16.2 4 91.0 67.0 38.0
394 16.4 6 181.0 110.0 25.0
395 17.0 6 262.0 85.0 38.0
396 14.5 4 156.0 92.0 26.0
397 14.7 6 232.0 112.0 22.0
398 13.9 4 144.0 96.0 32.0
399 13.0 4 135.0 84.0 36.0
400 17.3 4 151.0 90.0 27.0
401 15.6 4 140.0 86.0 27.0
402 24.6 4 97.0 52.0 44.0
403 11.6 4 135.0 84.0 32.0
404 18.6 4 120.0 79.0 28.0
405 19.4 4 119.0 82.0 31.0
Name Origin Weight_in_lbs Year
0 chevrolet chevelle malibu USA 3504 1970-01-01
1 buick skylark 320 USA 3693 1970-01-01
2 plymouth satellite USA 3436 1970-01-01
3 amc rebel sst USA 3433 1970-01-01
4 ford torino USA 3449 1970-01-01
5 ford galaxie 500 USA 4341 1970-01-01
6 chevrolet impala USA 4354 1970-01-01
7 plymouth fury iii USA 4312 1970-01-01
8 pontiac catalina USA 4425 1970-01-01
9 amc ambassador dpl USA 3850 1970-01-01
10 citroen ds-21 pallas Europe 3090 1970-01-01
11 chevrolet chevelle concours (sw) USA 4142 1970-01-01
12 ford torino (sw) USA 4034 1970-01-01
13 plymouth satellite (sw) USA 4166 1970-01-01
14 amc rebel sst (sw) USA 3850 1970-01-01
15 dodge challenger se USA 3563 1970-01-01
16 plymouth 'cuda 340 USA 3609 1970-01-01
17 ford mustang boss 302 USA 3353 1970-01-01
18 chevrolet monte carlo USA 3761 1970-01-01
19 buick estate wagon (sw) USA 3086 1970-01-01
20 toyota corona mark ii Japan 2372 1970-01-01
21 plymouth duster USA 2833 1970-01-01
22 amc hornet USA 2774 1970-01-01
23 ford maverick USA 2587 1970-01-01
24 datsun pl510 Japan 2130 1970-01-01
25 volkswagen 1131 deluxe sedan Europe 1835 1970-01-01
26 peugeot 504 Europe 2672 1970-01-01
27 audi 100 ls Europe 2430 1970-01-01
28 saab 99e Europe 2375 1970-01-01
29 bmw 2002 Europe 2234 1970-01-01
.. ... ... ... ...
376 chevrolet cavalier wagon USA 2640 1982-01-01
377 chevrolet cavalier 2-door USA 2395 1982-01-01
378 pontiac j2000 se hatchback USA 2575 1982-01-01
379 dodge aries se USA 2525 1982-01-01
380 pontiac phoenix USA 2735 1982-01-01
381 ford fairmont futura USA 2865 1982-01-01
382 amc concord dl USA 3035 1982-01-01
383 volkswagen rabbit l Europe 1980 1982-01-01
384 mazda glc custom l Japan 2025 1982-01-01
385 mazda glc custom Japan 1970 1982-01-01
386 plymouth horizon miser USA 2125 1982-01-01
387 mercury lynx l USA 2125 1982-01-01
388 nissan stanza xe Japan 2160 1982-01-01
389 honda Accelerationord Japan 2205 1982-01-01
390 toyota corolla Japan 2245 1982-01-01
391 honda civic Japan 1965 1982-01-01
392 honda civic (auto) Japan 1965 1982-01-01
393 datsun 310 gx Japan 1995 1982-01-01
394 buick century limited USA 2945 1982-01-01
395 oldsmobile cutlass ciera (diesel) USA 3015 1982-01-01
396 chrysler lebaron medallion USA 2585 1982-01-01
397 ford granada l USA 2835 1982-01-01
398 toyota celica gt Japan 2665 1982-01-01
399 dodge charger 2.2 USA 2370 1982-01-01
400 chevrolet camaro USA 2950 1982-01-01
401 ford mustang gl USA 2790 1982-01-01
402 vw pickup Europe 2130 1982-01-01
403 dodge rampage USA 2295 1982-01-01
404 ford ranger USA 2625 1982-01-01
405 chevy s-10 USA 2720 1982-01-01
[406 rows x 9 columns],
encoding: EncodingWithFacet({
color: Color({
shorthand: 'Origin'
}),
x: X({
shorthand: 'Horsepower'
}),
y: Y({
shorthand: 'Miles_per_Gallon'
})
}),
mark: 'point'
})
And similarly for the simpler version:
alt.Chart('nonexistent_file.csv').mark_line().encode(
x='x:Q',
y='y:Q',
)
I get
Chart({
data: 'nonexistent_file.csv',
encoding: EncodingWithFacet({
x: X({
shorthand: 'x:Q'
}),
y: Y({
shorthand: 'y:Q'
})
}),
mark: 'line'
})
lab extensions
jupyter labextension list
JupyterLab v0.32.1
No installed extensions
Jupyter lab itself
jupyter lab --version
0.32.1
Jupyter notebook itself
jupyter notebook --version
4.3.1
In the notebook (or lab), alt.version fails but alt.__version__ returns '2.0.1'
Doing jupyter labextension install @jupyterlab/vega3-extension
results in
ValueError: Please install nodejs 5+ and npm before continuing. nodejs may be installed using conda or directly from the nodejs website.
So I do conda install nodejs, which completes successfully and I do jupyter labextension install @jupyterlab/vega3-extension again and get no output at all. It just returns to command prompt. And I still get:
jupyter labextension list
JupyterLab v0.32.1
No installed extensions
Sorry you're having trouble! jupyter labextension list only lists external extensions, so if you have JupyterLab v0.32.1 installed, the vega extension is there even if it's not listed in the output of that command.
What I suspect is happening is that you've started a notebook with a kernel that does not match where you've installed this version of Jupyterlab.
Try re-launching JupyterLab, then choose File->New->Notebook and do not change the kernel in the "Select Kernel" window. Then try a plot in the resulting notebook.
Please let me know if that works!
Also, make certain you're launching JupyterLab, not Jupyter Notebook. For example, at the command prompt you should run
$ jupyter lab
not jupyter notebook.
From the output you pasted above, I suspect you were running the commands in jupyter notebook, not jupyter lab.
I created a new conda environment to try starting things fresh but I'm getting the same result.
$ conda create --name altair python=3.6
$ source activate altair
$ pip install jupyterlab altair
$ jupyter lab
It opened up the new browser tab with a "Select Kernel" dialog box. The dropdown only has one option: Python 3 (well there's also the option: "No Kernel"). I hit "Select".
Now I'm in Untitled1.ipynb in JupyterLab.
IN [1]: import altair as alt
from vega_datasets import data
iris = data.iris()
alt.Chart(iris).mark_point().encode(
x='petalLength',
y='petalWidth',
color='species'
)
OUT [1]: Chart({
data: petalLength petalWidth sepalLength sepalWidth species
0 1.4 0.2 5.1 3.5 setosa
1 1.4 0.2 4.9 3.0 setosa
2 1.3 0.2 4.7 3.2 setosa
3 1.5 0.2 4.6 3.1 setosa
4 1.4 0.2 5.0 3.6 setosa
5 1.7 0.4 5.4 3.9 setosa
6 1.4 0.3 4.6 3.4 setosa
7 1.5 0.2 5.0 3.4 setosa
8 1.4 0.2 4.4 2.9 setosa
9 1.5 0.1 4.9 3.1 setosa
10 1.5 0.2 5.4 3.7 setosa
11 1.6 0.2 4.8 3.4 setosa
12 1.4 0.1 4.8 3.0 setosa
13 1.1 0.1 4.3 3.0 setosa
14 1.2 0.2 5.8 4.0 setosa
15 1.5 0.4 5.7 4.4 setosa
16 1.3 0.4 5.4 3.9 setosa
17 1.4 0.3 5.1 3.5 setosa
18 1.7 0.3 5.7 3.8 setosa
19 1.5 0.3 5.1 3.8 setosa
20 1.7 0.2 5.4 3.4 setosa
21 1.5 0.4 5.1 3.7 setosa
22 1.0 0.2 4.6 3.6 setosa
23 1.7 0.5 5.1 3.3 setosa
24 1.9 0.2 4.8 3.4 setosa
25 1.6 0.2 5.0 3.0 setosa
26 1.6 0.4 5.0 3.4 setosa
27 1.5 0.2 5.2 3.5 setosa
28 1.4 0.2 5.2 3.4 setosa
29 1.6 0.2 4.7 3.2 setosa
.. ... ... ... ... ...
120 5.7 2.3 6.9 3.2 virginica
121 4.9 2.0 5.6 2.8 virginica
122 6.7 2.0 7.7 2.8 virginica
123 4.9 1.8 6.3 2.7 virginica
124 5.7 2.1 6.7 3.3 virginica
125 6.0 1.8 7.2 3.2 virginica
126 4.8 1.8 6.2 2.8 virginica
127 4.9 1.8 6.1 3.0 virginica
128 5.6 2.1 6.4 2.8 virginica
129 5.8 1.6 7.2 3.0 virginica
130 6.1 1.9 7.4 2.8 virginica
131 6.4 2.0 7.9 3.8 virginica
132 5.6 2.2 6.4 2.8 virginica
133 5.1 1.5 6.3 2.8 virginica
134 5.6 1.4 6.1 2.6 virginica
135 6.1 2.3 7.7 3.0 virginica
136 5.6 2.4 6.3 3.4 virginica
137 5.5 1.8 6.4 3.1 virginica
138 4.8 1.8 6.0 3.0 virginica
139 5.4 2.1 6.9 3.1 virginica
140 5.6 2.4 6.7 3.1 virginica
141 5.1 2.3 6.9 3.1 virginica
142 5.1 1.9 5.8 2.7 virginica
143 5.9 2.3 6.8 3.2 virginica
144 5.7 2.5 6.7 3.3 virginica
145 5.2 2.3 6.7 3.0 virginica
146 5.0 1.9 6.3 2.5 virginica
147 5.2 2.0 6.5 3.0 virginica
148 5.4 2.3 6.2 3.4 virginica
149 5.1 1.8 5.9 3.0 virginica
[150 rows x 5 columns],
encoding: EncodingWithFacet({
color: Color({
shorthand: 'species'
}),
x: X({
shorthand: 'petalLength'
}),
y: Y({
shorthand: 'petalWidth'
})
}),
mark: 'point'
})
So, you didn't install vega_datasets, but you imported it successfully. That tells me that the kernel you are using in your notebook doesn't match the environment where you installed jupyterlab and altair.
Something is strange with your conda environments & jupyter kernels.
What is the result of alt.__version__?
The only way I can think of that you would get this output in JupyterLab is if you're using version 1.2 or older (even if the vega renderer is not working, JupyterLab would display the text/plain output, which looks like <VegaLite 2 object>. Unless you're using an older version of Altair, in which case it will show this output).
In [2]: alt.__version__
Out [2]: '2.0.1'
Very strange... what happens if you run this code in your notebook?
class Test(object):
def _repr_mimebundle_(self, include, exclude):
return {'text/plain': "Mimebundle Repr"}
def __repr__(self):
return "Normal Repr"
Test()
Out[3]: Normal Repr
OK – what that tells me is that you're using a kernel that does not support mimebundle rendering, which is what JupyterLab uses to display Altair charts. This was true of very old versions of IPython
I'm even more convinced now that your notebook is connected to an old ipython kernel that you created a while ago.
What is the output of this command at the command line?
$ jupyter kernelspec list
I normally work in an environment called py36. In there I also only have 1 kernel (Python 3). That's the environment where I initially did all of the installation steps for this. When I made my new altair environment, I did that call from py36 but I didn't explicitly tell it to copy anything from py36. 🤔
When I'm in my new altair environment
$ jupyter kernelspec list
Available kernels:
python3 /Users/jmason86/Library/Jupyter/kernels/python3
When I'm in my default environment (new terminal window):
jupyter kernelspec list
Available kernels:
python2 /Users/jmason86/anaconda/lib/python2.7/site-packages/ipykernel/resources
python3 /Users/jmason86/Library/Jupyter/kernels/python3
When I'm in my typical py36 environment (where I did my original altair, etc installations:
$ jupyter kernelspec list
Available kernels:
python3 /Users/jmason86/Library/Jupyter/kernels/python3
Bingo. You need to remove or rename that kernel. When you have a kernel called python3, it becomes the default kernel for any notebook launched from a Python 3 environment... what that means is you're unable to connect your notebook to the current Python 3 conda environment that you're using.
I suspect if you ran import sys; sys.executable in your notebook, it would point to a different Python installation than the one in the conda environment you created.
What I would do is rm -r /Users/jmason86/Library/Jupyter/kernels/python3, and then re-launch jupyterlab.
Alternatively, if you don't want to delete that kernel, you should update the jupyterlab, jupyter, ipython, and notebook packages in whatever python environment is pointed to inside /Users/jmason86/Library/Jupyter/kernels/python3/kernel.json.
Okay, did the rm -r and now it's complaining that it can't find vega_datasets, as expected.
Nice :smile: I think if you install vega_datasets now things should work...
Congratulations on hitting the deepest, darkest corner case in the entire Jupyter ecosystem

THANKS! For the debugging and the super speediness!
Most helpful comment
THANKS! For the debugging and the super speediness!