Altair: Gallery examples that use altair.expr module

Created on 26 Mar 2018  Â·  21Comments  Â·  Source: altair-viz/altair

All 21 comments

Sorry for the confusion – we removed the old bloated expr module before adding back in a new version of the expr module. It will stay, and those examples will continue to function.

perhaps I have to do the 'run from master' (python setup.py install) technique? My 2.0.0rc1 install via conda install altair jupyterlab --channel conda-forge doesn't seem to include the updated code

It depends what you want to do... if you install 2.0.0rc1 then you should have the expr module installed as well.

Try running

import altair as alt
print(alt.__version__)
print(alt.__path__)

to make certain you're importing the version you think you're importing.

Oh, you can't install 2.0.0rc1 via conda-forge... you need to install it via pip.

If you did conda install altair, then you have altair version 1.3.

For version and path, I get:

2.0.0dev
['/usr/local/lib/python3.6/site-packages/altair-2.0.0.dev0-py3.6.egg/altair']

and when I do !pip freeze | altair
I get

altair==2.0.0rc1

screen shot 2018-03-26 at 11 56 28 am

That's very strange... were these cells run with the same kernel? I see that the top cell has execution count 4 and the bottom cell has execution count 1. Can you restart the kernel and then run these in sequence?

same result after restarting the kernel screen shot 2018-03-26 at 12 57 17 pm

I also did a conda uninstall altair, just in case that was a factor

The execution count was likely because I collapsed the !pip freeze into one cell so it would fit in the screenshot

OK, so you're not actually running 2.0.0rc1... the !pip freeze is not associated with the kernel you are using in your jupyterlab session. In Jupyter, you're using 2.0.0dev, and I suspect your 2.0.0dev install is from a while ago if altair.expr is not available.

So basically, you pip installed Altair 2.0.0rc1 in one Python kernel, and you're running Jupyterlab on another kernel, so you're importing an old version of Altair.

This is one of the biggest warts of the jupyter multi-kernel model right now. I suspect if you run

!which python

and

import sys; print(sys.executable)

you will see different executables.

I wrote a whole blog post about this issue; you can read it here: https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/

What you need to do is make certain you have installed altair in the kernel you're using in JupyterLab. The easiest way to do this is probably to exit Jupyterlab, run the pip install command, open JupyterLab, and open a new notebook with the default Python 3 kernel, which matches the executable used to start JupyterLab.

Let me know how it goes.

Indeed, they were two different executables
One was
/Users/marjorieroswell/anaconda2/envs/py36/bin/python
and the other was the regular python36 path

I've tried a slew of things, and still no luck..

I'm running a conda environment, that in the terminal has pip installed altair. But now that both are consistently using the conda36 environment, I'm getting ImportError: No module named altair even though in the terminal, it shows I've got altair==2.0.0rc1

I'm going to try to use regular virtualenv to get a python3 environment, to see if I have any better luck that way.

actually, before I do that, I'll see if I can work my way through your blog post.

Are you using Conda environments, or just the root environment?

Using Conda environments.

On Mon, Mar 26, 2018 at 8:35 PM Jake Vanderplas notifications@github.com
wrote:

Are you using Vonda environments, or just the root environment?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/altair-viz/altair/issues/657#issuecomment-376356576,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AALwOFtsvxp4B00ndX_hyIZP_-KcWYBrks5tiYlCgaJpZM4S6zWa
.

>

--
http://CommitteeMaps.org
http://SugarWars.com

Ah, I know what's happening then. I suspect you're creating a conda environment, installing Altair in it, and not installing JupyterLab. This means that when you run jupyter lab it's running it in a different environment than your Altair installation.

So you need to make an environment:

$ conda create -n altair-test python=3.6
$ source activate altair-test

and then follow the installation instructions from https://altair-viz.github.io/getting_started/installation.html#installing-altair-with-jupyterlab including installing JupyterLab (don't skip that step)

$ pip install altair==2.0.0rc1
$ pip install jupyterlab
$ jupyter labextension install @jupyterlab/vega3-extension

Now you can run jupyter lab, then open a new notebook with the "Python 3" kernel, and then plots should work.

If you forget to install jupyterlab in the new environment, then launching juptyerlab will use the executable from the root environment, and plots won't work.

If you open a notebook with the wrong kernel, then it won't have access to the altair version that you installed, and plots won't work.

Hope that helps

To the helpful instructions you provided above, I added:
python -m ipykernel install --name altair-test
before I ran jupyter lab
and switched to the altair-test kernel

Then after overcoming all the installation challenges, I had to remember to actually print the chart in the gallery examples!

It might be helpful if each gallery example ended with
chart
so that each chart prints by default with a simple copy-paste. (Would that work, or would it somehow mess up the appearance of the chart in the documentation?)

A note that the guidance here:
https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/
seems to behave differently.

For instance, success didn't require me to do this in the Jupyter lab
!{sys.executable} -m pip install altair==2.0.0rc1

I just did
pip install altair==2.0.0rc1
at the terminal

Given this tweet, and that others are encountering a range of similar issues:
https://twitter.com/akarve/status/978442506118471680
it would probably be helpful if someone provided a video of things that can go wrong, and how to fix 'em...

In any case, the altair.expr import are now working for me. (I'm not yet confident that I can talk others through it.)

I think part of the challenge is that I don't exactly understand what a Jupyter lab/notebook kernel is. Maybe in addition to the if-this-goes-wrong-then-do-that, it might help to explain why

import sys; 
print(sys.executable)

and

!which python

yield different results, and how that relates to executables and Jupyter Lab kernels.

In essence:

  • It's working for me (yay!) but my guess is that others will need to be talked through similar issues... Some video content to assist might help.
  • Does the addition of python -m ipykernel install --name altair-test to the instructions seem to make sense (along with switching to the newly-added kernel)? (I think that's what worked for me.)
  • I gather !{sys.executable} -m pip install altair==2.0.0rc1 is not necessary to be run inside the Jupyter lab?
  • Can chart be added to the end of all of the gallery samples?

Given this tweet, and that others are encountering a range of similar issues:
https://twitter.com/akarve/status/978442506118471680
it would probably be helpful if someone provided a video of things that can go wrong, and how to fix 'em...

That's why I wrote that blog post... note that the blog post is not an attempt to help people install Altair, but an attempt to help people understand why pip install / conda install doesn't always put things in the place you might naively expect them to. More of a "here's the background you need to know in order to solve these problems yourself" kind of thing. Though I admit I probably could have done a better job at it.

Does the addition of python -m ipykernel install --name altair-test to the instructions seem to make sense (along with switching to the newly-added kernel)? (I think that's what worked for me.)

No, I think this adds too much confusion, because it's unnecessary. You just need to choose the Python 3 kernel (which in this case is now identical to the altair-test kernel) This is why in the installation instructions I emphasize "Choose the Python 3 kernel". As long as you follow the installation instructions exactly, it will work.

I gather !{sys.executable} -m pip install altair==2.0.0rc1 is not necessary to be run inside the Jupyter lab?

No, the only thing that is necessary is to follow the exact installation instructions given in the docs. That pattern from the (unrelated) blog post is what you need if you want to install a package within an already running jupyter notebook, which is orthogonal to the altair installation question.

Can chart be added to the end of all of the gallery samples?

That could be helpful.

I think the best option is to point people to Colab, now that it's working. There are just too many variables in play with JupyterLab/Jupyter notebook + jupyter extensions/ipyvega + conda envs/pip envs + exact versions needed + confusion about installation and execution paths.

Good to know about Colab!!
https://research.google.com/colaboratory

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bmcfee picture bmcfee  Â·  3Comments

tonylee3399 picture tonylee3399  Â·  3Comments

HalukaMB picture HalukaMB  Â·  3Comments

morberg picture morberg  Â·  3Comments

floringogianu picture floringogianu  Â·  3Comments