Closed ijlyttle closed 6 years ago
Hi – the two import statements are not equivalent. from vega_datasets import data
will import the data
object from the vega_datasets
module. On the other hand, import vega_datasets.data as data
imports the submodule named vega_datasets.data
, rather than the data
object that is within the vega_datasets
module.
Because the data
object used by vega_datasets
is not a module, there's no way that we can make import vega_datasets.data as data
do what you want it to do. It is only possible to import a submodule this way, not an object from a module.
The reason it works for scipy.stats
is because scipy.stats
is a module object, not an object defined within the scipy
namespace.
I hope that clears things up!
I've pushed a fix in #10 that will alleviate this confusion. Now doing import vega_datasets.data as data
will raise an ImportError
.
Thanks! Reading your explanation, I should have used the word "hope" instead of "expect" ;)
When I run
import altair as alt
from vega_datasets import data
I am getting the error:
ModuleNotFoundError Traceback (most recent call last)
in () 1 import altair as alt ----> 2 from vega_datasets import data 3 4 iris = data.iris() 5 ModuleNotFoundError: No module named 'vega_datasets'
Any thoughts why?
It almost looks like the package vega_datasets
is not installed.
Thanks, @ijlyttle. How do I install the package vega_datasets?
No problem, try this: https://github.com/altair-viz/vega_datasets#installation
Solved. Thanks, @ijlyttle.
Please forgive me as I am a Python "newbie" and may be asking an ignorant question.
I would like to be able to use the form:
instead of
My motivation is that I can use something analogous to the first form when using the
import()
function in the R reticulate package.If I try this (in Python):
I get (as I expect):
However, if I try this:
I get:
whereas I am hoping to replicate the first behavior.
By contrast, this works as I expect:
Question: could it be possible for
import vega_datasets.data as data
to work likefrom vega_datasets import data
?Thanks!