No module named 'ipywidgets'

(Li Ma) #1

Hi , I am a beginner to the course. In lesson 2 notebook, i tried the code of ‘from fastai.widgets import *’ but it errored out that ’ No module named ‘ipywidgets’’ . I am using Amazon sagemaker with fast ai kernel. I checked conda package and there is ipywidgets. And i also tried pip install ipywidgets. But it still shows the same error. i am not sure what the reason is.

(William Duvall) #2

Did you try !pip freeze | grep ipywidgets from within the notebook, or !which python in the notebook and which python in the terminal? You can possibly have multiple different versions of python installed. If you install a package in a terminal for a different python instance, you will not be able to use when you are in the notebook. You can also use the ! symbol from within the notebook with pip or conda to install packages.

(Aaron Yang) #3


I’m getting the same error too. I’m running in azure.

I also dont have permissions to download pip, so i cant pip install the ipywidgets into my environment.

(Li Ma) #4

Hi Will, thanks for your reply. I tried !pip freeze | grep ipywidgets within notebook and it did not have any effects on the error I got. I tried !which python in the notebook and it shows as /home/ec2-user/SageMaker/envs/fastai/bin/python
Then I tried which python in the terminal , it showed /home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin/python
But I am not sure how to check if they are same package. I would assume the notebook use the same package as the terminal. If not, how can i install the package into notebook?
Thank you!

(Li Ma) #5

Hi I added !pip install ipywidgets into the notebook and it works. Will, you are right. Looks like the notebook and terminal not synced with the same python package.

(Matthew Arthur) #6

I pip installed ipywidgets and restarted but my notebook, in Sagemaker, still throws the error. Thoughts?

(Aaron Yang) #7

(Aaron Yang) #8

figured its a kernel issue with azure’s I can use pip if i switch the kernel from Python(fastai) to a Python 3.5. This is impeding on my ability to follow the course… what should i do?

(Michael Rademaker) #9

I solved this by cloning my conda environment from a shell

$ conda create --name fastaiv2 --clone fastai

activating it

$ conda activate fastaiv2

installing ipywidgets into it

(fastaiv2) $ conda install ipywidgets

and registering that env as a jupyter notebook kernel

(fastaiv2) $ python -m ipykernel install --user --name fastaiv2 --display-name "Python (fastAI v2)"

Selecting that kernel in my notebook seemed to do the trick to import ipywidgets and run notebook2!

(Chrisada Sookdhis) #10

Can we just install into the original conda environment?

(Mario Kostelac) #11

Yes, just run following code from Jupyter env

import sys
!conda install --yes --prefix {sys.prefix} ipywidgets

Others, if installing from Jupyter env, please run with --yes --prefix {sys.prefix} to make sure it lands in correct environment.
If using pip, do

!{sys.executable} -m pip install ipywidgets

Not adding these prefixes is very often not enough if ran from Jupyter notebook.

If you’re interested in more, you can read about it on (yes, it’s mine, i wrote it because i saw many people having these struggles)