Cannot Import fastai vision: ValueError: module functions cannot set METH_CLASS or METH_STATIC

I am unable to import fastai vision in Google Colab.

I am first installing fastai-

%%bash
pip uninstall fastai -y > /dev/null
pip install fastai > /dev/null

Then, when I proceed to import the vision namespace like-

from fastai.vision.all import *

I see this error-

ValueError: module functions cannot set METH_CLASS or METH_STATIC

Full Error Message
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-5635efd54484> in <module>()
----> 1 from fastai.vision.all import *

4 frames
/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 *

/usr/local/lib/python3.7/dist-packages/fastai/vision/models/__init__.py in <module>()
----> 1 from . import xresnet
      2 from . import unet
      3 from .tvm import *

/usr/local/lib/python3.7/dist-packages/fastai/vision/models/xresnet.py in <module>()
     10 
     11 # Cell
---> 12 from ...torch_basics import *
     13 from torchvision.models.utils import load_state_dict_from_url
     14 

/usr/local/lib/python3.7/dist-packages/fastai/torch_basics.py in <module>()
----> 1 from torch import multiprocessing
      2 import platform,os
      3 if platform.system()=='Darwin':
      4     # Python 3.8 changed to 'spawn' but that doesn't work with PyTorch DataLoader w n_workers>0
      5     multiprocessing.set_start_method('fork', force=True)

/usr/local/lib/python3.7/dist-packages/torch/__init__.py in <module>()
    195     if USE_GLOBAL_DEPS:
    196         _load_global_deps()
--> 197     from torch._C import *  # noqa: F403
    198 
    199 # Appease the type checker; ordinarily this binding is inserted by the

ValueError: module functions cannot set METH_CLASS or METH_STATIC

I have never seen this error before. What do I do?

This is how I solved it.

I first Factory Reset Runtime from Runtime → Factory Reset Runtime.

Then I uninstalled and installed fastai, torch, and torchvision.

%%bash
pip uninstall fastai -y > /dev/null
pip install fastai > /dev/null
pip uninstall torch -y > /dev/null
pip install torch > /dev/null
pip uninstall torchvision -y > /dev/null
pip install torchvision > /dev/null

That solved the problem, and no more error messages appeared, and everything is working as expected.