AttributeError: 'NoneType' object has no attribute 'mkdir'

Friends, on Paperspace, trying to go through 04_mnist_basics.ipynb

Cells 1 and 2 execute w/o error.
But when I try to run cell 3, which is:

path = untar_data(URLs.MNIST_SAMPLE)

I get this error:

AttributeError: ‘NoneType’ object has no attribute ‘mkdir’

Any help or suggestions appreciated very much.

1 Like

This works for me with an fresh paperspace instance. You could try untar_data(URLs.MNIST_SAMPLE, force_download=True) to re-download the .tgz which might be broken or alternatively run untar_data(URLs.MNIST_SAMPLE, archive='tmp' data='tmp') to change the download / data folder and have a ‘fresh start’ this way.
If this doesn’t work you would need to give us more information about the error, so post the whole stack trace otherwise we can only guess what’s the issue :wink:

The first suggestion produced the same error but your second suggestion worked like a charm! Cell executed w/o error and I was able to move forward. Thanks, Ben!

:point_down:
untar_data(URLs.MNIST_SAMPLE, archive=‘tmp’, data=‘tmp’)

Happy it worked :slight_smile:
…but now im curious :laughing: Would you mind checking where fastai downloads/extracts the data to by default:

print(fastai_cfg().path('archive'))
print(fastai_cfg().path('data'))

and check what those paths hold?

!ls {fastai_cfg().path('archive')}
!ls {fastai_cfg().path('data')}

It might not be important in this case, since MNIST_SAMPLE is tiny, but you don’t want to bloat your storage with unused data…

Sure thing. Attached are two screenshots that should give you the info you seek.

Are you surprised by the results?

(p.s. Also, thanks very much for your help. I’ve been working in isolation on Fastai for 3 months in my spare time and you’re the first community member I’ve interacted with to date! Big confidence booster for me!)

Screen Shot 2022-10-17 at 7.32.34 PM
Screen Shot 2022-10-17 at 7.32.19 PM

Sorry for the delay… Apparently calling untar_data with those parameters makes fastai_cfg return the changed paths, but I was interested in the default ones :face_with_diagonal_mouth:
I also don’t want to take more of your time, so I just leave this here in case someone tries to resolve a similar issue:

The default paths are saved in a config.ini file at fastai_cfg().config_file

from fastai.data.all import fastai_cfg
!cat {fastai_cfg().config_file}

for me returns

[DEFAULT]
archive = /storage/archive/
model = /storage/model/
data = /storage/data
storage = /storage/data/

on paperspace. You can also access those paths as described in my previous post or with fastai_cfg()['data'] for example. Note that ‘non absolute’ paths in the config.ini are usually relative to ~/.fastai.
…anyways, when something went wrong with the download or extraction you can check these locations and remove the concerned file/folder and start over.

Also, changes made by untar_data are not persistent, so even if you’re happy with the solution above, you have to remember to pass the same folders to untar_data if you want to use the downloaded data in a different notebook :slight_smile: .
You could make persistent changes to the config with:

fastai_cfg().__setitem__('data', 'something') # the other paths respectivly
fastai_cfg().save()

(or use an editor to change config.ini) and wouldn’t have to pass the archive and data parameters to untar_data.

You’re very welcome :slight_smile:

2 Likes

I just ran into the same problem (also on paperspace):

config.ini is missing a location for the archive to be placed in:

[DEFAULT]
data = data
storage = tmp
model = models

I added the archive folder by doing:

from fastai.data.all import fastai_cfg
fastai_cfg()['archive'] = 'archive'
fastai_cfg().save()

After that the config.ini reads:

[DEFAULT]
data = data
storage = tmp
model = models
archive = archive

After which untar_data works again and the downloaded archive is placed in the ~/.fastai/archive folder.