Skip to content
python sklearn import bug in classrooms
Profile icon

Module import works fine in a standalone repl but not always within a classroom e.g. try

import sklearn

within a classroom and you'll see the error:

ModuleNotFoundError: No module named 'sklearn'

As I say, things work fine in a standalone repl where this line caused the following output:

Collecting scikit_learn
Downloading (6.7MB)

Anyone else see this behaviour too ?

You are viewing a single comment. View All
Profile icon

here's a workaround for this issue in classrooms (it doesn't arise in standlone scripts). add the following to import sklearn manually:

i’ve posted a workaround for this on blackboard. add the following lines at the top of

import sys
import subprocess
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'sklearn'])

its not nice, and it would be better of the good folks fixed up importing of module dependencies in classrooms to be like that for standalone scripts.