No module named 'ipywidgets'

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.

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.

1 Like

Following

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

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

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!

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.

1 Like

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

1 Like

figured its a kernel issue with azure’s fast.ai. 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?

1 Like

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!

2 Likes

Can we just install into the original conda environment?

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 https://biasandvariance.com/2019/02/07/importing-packages-in-jupyter-notebooks/ (yes, it’s mine, i wrote it because i saw many people having these struggles)

3 Likes

I have the exact same problem here

And this one solved it, thank you @mariokostelac