TypeError: 'NoneType' object is not iterable at lesson 2


Everything works just fine in Colab until this point. is this one of those problem cause by the new fastai version update? Thank you in advance

Thanks for the information

'nonetype ’ object is not iterable occurs when you try to iterate any objects or variable having or assigned “None” value.

Yes, I get that. But I just followed the fastai notebook. Why would this happen? I kind of solved it by not using the Azure api and instead using duckduckgo image search api but that doesn’t explain why this error happens. Did I not download the images correctly?

It may be worth to check whether you have images in the folder where path is pointing.
You can do something like [f for f in path.iterdir() if f.is_file()] or [f for f in Path(path).iterdir() if f.is_file()] to get the list of files in the folder. (which code works will depend on what path is: a string or a pathlib Path.
If there are not images, of if path is not a proper path, then it means there was problem higher in the loading of images.

Hope it helps.

I had the same issue and the solution was an incomplete creation of the bears folder, just delete the folder and rerun the cell blocks to create them properly.

What I think caused this was when I was first running this I was fairly anxious about being charged for api usage on azure, so I stopped it part way through to make sure I wouldn’t, and it created the bears folder, and the grizzly subfolder, but missing teddy and black. However running the cells again never properly remade it or added the other 2 folders and was returning a non type, super weird, took me like a week to notice after I was comparing running it in a fresh environment just by chance and noticed that the folders where off and looking through the files presuming the error came from the code block above the error containing mkdir.

1 Like

I’m having the same problem, and it is not yet resolving. I’m in Kaggle and it is Nov 2023

  • bears contains only grizzly after NoneType errors
  • I removed bears and re-ran: same results.
  • Seems like the for loop isn’t executing - is it an indentation problem? Put the for loop in it’s own code block. Same results.

I just reran all the cells and it worked without any error, thank you!