ModuleNotFoundError: No module named 'fastai.vision.all' on Kaggle Notebook

I ran the code from the fastai book to import the fast ai library in a Kaggle Notebook and it gave an error.
from fastai.vision.all import *

But removing ‘.all’ from the code worked just fine. Is the book yet to updated?

4 Likes

you are probably using the older version of fastai.
fastai now refers to fastai v2. You’ll need to upgrade your library
Type pip install fastai --upgrade in the command line. You should be good to go!
You’ll also need to install fastcore, if you haven’t done it before! Cheers

7 Likes

I tried that and it didn’t work either.
This is the error I am getting.
ModuleNotFoundError: No module named ‘fastai.callback.all’; ‘fastai.callback’ is not a package

I tried but I am unable to find the notebooks for this course, do we have to the book only?

I dont know why its so! I tried on my instance and it works. It definitely is an installation issue!

I don’t know if kaggle will let you, but you may want to try installing fastbook with:

conda install fastbook -c fastai

1 Like

I dont understand how its an installation issue since I’m using a Kaggle Notebook and just using the code to import the necessary libraries.

oh i see. I think kaggle hasnt updated the libraries on the backend? I dont know for sure, I havent used kaggle before!

1 Like

It isnt even working on Google Colab.
Should I write a new post to address this?

2 Likes

I had the same errors, but it worked after I did “pip install fastai --upgrade”. I’m running the course v4 notebook https://github.com/fastai/course-v4 on google cloud platform.

2 Likes

@NoBlueWithoutYellow I did check on colab. It is working there.
On colab, you would type:
pip install fastai --upgrade and then restart your runtime. Then it should work just fine!

15 Likes

Hello @NoBlueWithoutYellow

I also see this issue intermittently. (It tends to be when I have left the colab notebook for a while and come back to it, Not sure though. I guess its some sort of session related issue with colab.)

I’ve found deleting my copy of the colab notebook and then starting over fixes the issue.
(Make sure you have a copy of any new code in a safe place. etc)

  1. So I go to my google drive, and delete the “Copy of …” version of the notebook there.
  2. Open a new copy from fastai/course-v4 in github
  3. Save that to my google drive
  4. Set the notebook settings to GPU
  5. Click play on the first code cell, and all is fine again.

Hope that helps.

2 Likes

First print out your fastai’s version to see whether it is version 1.xx.
print(fastai.version)
If it is, try to install fastai v2
!pip install fastai==2.0
It should work.

1 Like

I was having the same problem on Google Colab and this worked for me:

!pip install fastai==2.0
import fastai
print(fastai.__ version __ ) # should be 2.0.0
from fastai.vision.all import *

hope it helps!

(note that the print statement has blank characters before and after “version”. Remove them if you copy paste. (They are there so it doesn’t become like this: print(fastai.version ))

2 Likes

I am using Google Colab. I have upgraded fastai to fastai 2.0.
When i run " from fastai.vision.all import * " i am facing this error,
can you guys please help me?

Thank you in advance

AttributeError Traceback (most recent call last)
in ()
----> 1 from fastai.vision.all import *

9 frames
/usr/local/lib/python3.6/dist-packages/fastcore/utils.py in store_attr(names, self, but, **attrs)
95 args,varargs,keyw,locs = inspect.getargvalues(fr)
96 if self is None: self = locs[args[0]]
—> 97 if not hasattr(self, ‘stored_args’): self.stored_args = {}
98 if attrs: return _store_attr(self, **attrs)
99

AttributeError: ‘str’ object has no attribute ‘stored_args

1 Like

That is because you are installing version 2.0.0 and there have been changes since, the latest version is 2.0.8.

Use:
!pip install fastai --upgrade -q instead and for the moment you will have to downgrade pandas so it is compatible with colab

2 Likes

okk… :sweat_smile: Thank you for your help

2 Likes

Most relevant thing I’ve found after 2 days–but can you please explain to a newbie how to “downgrade pandas so it is compatible with colab”. Thank you in anticipation. (And PS: what are the symptoms that allow one to know to do this? --low priority–I can try it and see.)

1 Like

Glad the info helped :slight_smile: Actually just using:

!pip install fastai --upgrade -q

in colab should do the trick, no need to downgrade pandas any more. That post was a couple of weeks ago and at that point there was a compatibility issue with pandas.

1 Like

Thank you so much; I have finally managed to break the load_learner barrier.
FYI: (actually for the information of other lost souls who arrive here):

Cut back to just the above upgrade and the original’s first from fastai.vision.widgets import *; restarted; clear all; run all

result still NameError: name ‘Path’ is not defined

Added from pathlib import Path

result name ‘load_learner’ is not defined

Added from fastai import * – no improvement

Added **from fastai.basics import *** – this was a w-a guess based on the autocomplete when I was trying to type “basic_train” – it shouldn’t be so obscure. I really thought Colab was the lowest threshold point of entry, but undocumented it certainly can’t work as fastai-for-newbies playground.


Now on to the next hurdle…

.

Proud to say after one more
from fastai.vision.all import *
I uploaded a ginger cat and got it classified as teddy bear with 99% confidence.