ImportError: cannot import name 'load_learner' from 'fastai'

Based on Stack Overflow post.

I’m new to fastai.

  • fastai 2.7.5
  • fastcore 1.4.5
  • nbdev 1.2.10
  • torch 1.12.0
  • torchvision 0.13.0
from fastai import load_learner

learn = load_learner('export_2.pkl', cpu=False)

>>> ImportError: cannot import name 'load_learner' from 'fastai' (/home/daniel/miniconda3/envs/pdl1lung/lib/python3.9/site-packages/fastai/__init__.py)

You want from fastai.learner import load_learner

Or just do from fastai.vision.all import *

1 Like

When I do (which is what I really want):

fastai.vision.all import *

Or your suggested:

from fastai.learner import load_learner

Both give:

NameError: name 'defaults' is not defined

I detail this on a separate Stack Overflow post.

Might be something with your install, this worked just fine for me so not sure what the error is.

fastai 2.7.5, fastcore 1.4.5

I have those versions ;(

from fastai.vision.all import *
conda create -n venv python==2.6.13
pip install -r requirements.txt

requirements.txt:

fastai==2.5.3
fastcore==1.3.27
python==3.6.13

Your issue here is fastai is only for python 3.7+

So do:

conda create -n venv python==3.7
1 Like

Sorry ! Typo… I did mean to say python3.6.13 Sorry

fastai no longer supports python 3.6 as it hit its EOL at the beginning of this year

1 Like