ERROR: torchtext 0.9.1 has requirement torch==1.8.1, but you'll have torch 1.7.1 which is incompatible

I am working on Google Colab.

I tried importing fastai without installing it by-

from fastai.vision.all import *

But it failed, and so I went on to pip install it by-

%%bash
pip uninstall fastai -y
pip install fastai

But this gives me the error mentioned in the title-

ERROR: torchtext 0.9.1 has requirement torch==1.8.1, but you’ll have torch 1.7.1 which is incompatible.

When I go ahead and try to import fastai vision import anyway, I get this-

ModuleNotFoundError: No module named ‘fastai.callback.all’; ‘fastai.callback’ is not a package

See full error message
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-4-e0ad1b014401> in <module>()
      1 import platform
      2 import fastai
----> 3 from fastai.vision.all import *
      4 import sklearn
      5 import torch

/usr/local/lib/python3.7/dist-packages/fastai/vision/all.py in <module>()
      1 from . import models
      2 from ..basics import *
----> 3 from ..callback.all import *
      4 from .augment import *
      5 from .core import *

ModuleNotFoundError: No module named 'fastai.callback.all'; 'fastai.callback' is not a package

How do I circumvent this?

2 Likes

Weird thing happened.

I was doing this-

%%bash
pip uninstall fastai -y
pip install fastai

Didn’t work.

But when I did this-

! pip uninstall fastai -y
! pip install fastai

It worked. No dependency error or anything.

No idea why this is happening.

I am marking this as solved, but I still can’t explain why this happened.

Edit: problem occurred again.

Even when the problem appears, i.e. the error message appears, it did not affect my workflow working with a vision project. Dataloading was successful, the model trained, and everything else worked as expected despite the error message.

If you do not want the error message, you can either-

!pip install torchtext==0.8.1
!pip install -U fastbook

as suggested by @muellerzr here,

or you could use light-the-torch-

!pip install light-the-torch
!ltt install torch torchvision
!pip install fastai --upgrade

also suggested by him.

You should know that not using IPython magic does not make the problem go away. It was mere chance.