Unable to execute untar_data

Hello.

I am new to python, data science and trying to follow along by working on some examples in fastAi book. Running into this issue: When I do “path = untar_data(URLs.MNIST_SAMPLE)” I get the error. i already did !pip install -Uqq fastai. so not sure why untar_data is throwing up an error.

NameError Traceback (most recent call last)
/tmp/ipykernel_27/4241633610.py in
----> 1 path = untar_data(URLs.MNIST_SAMPLE)

NameError: name ‘untar_data’ is not defined

Hey @kalrapawan,

You’ll want to make sure you’ve imported the untar_data method from the fastai library, here are the docs in the library showing the module you can import it from.

However It’s much easier to import from the .all module instead of the singular method directly, try running:

from fastai.vision.all import *

and then calling the untar_path method, you should get an output something like the following:

In [1]: from fastai.vision.all import *

In [2]: path = untar_data(URLs.MNIST_SAMPLE)

In [3]: path
Out[3]: Path(‘C:/Users/Nick/.fastai/data/mnist_sample’)

Otherwise you can import it directly by having the following import statement but I think the above is easier!

from fastai.data.external import untar_data

Hope that helps :smiley:

1 Like

Thank you, It works.

1 Like