Week 1 Optional lab 03: Cost Function

Hi guys,

The code in optional lab runs without a problem.

But when I copied all the files on my PC and want to run them on Jupyter Notebook, I get the following Traceback Message

--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last)

RuntimeError: ‘widget’ is not a recognised backend name During handling of the above exception,

RuntimeError: 'widget is not a recognised GUI loop or backend name

Does anyone have an idea what might be going wrong?

You have to install the same versions of all of the tools that Coursera uses.

This means the versions of Python, numpy, scikit, TensorFlow, etc.

Ok. I will check it out. Thank you!

Did you solve the problem?
if yes, how? and which versions are you downloading or using other than the newest version?

1 Like

The optional labs are very rarely updated, and since you don’t have to edit any of their contents, you just run them cell by cell.

Hi, on MacOS Sonoma 14.5, with:

  • Python 3.12.3
  • Jupyter 1.0.0
  • Jupyter widgets 3.0.11
    running the notebook in JetBrains PyCharm 2024.1.1, commenting out the line %matplotlib widget below worked for me.
import numpy as np
# %matplotlib widget
import matplotlib.pyplot as plt
from lab_utils_uni import plt_intuition, plt_stationary, plt_update_onclick, soup_bowl
plt.style.use('./deeplearning.mplstyle')
1 Like

Commenting the line didn’t help.
Then I get “ModuleNotFoundError: No module named ‘ipywidgets’”

Are you running the lab on Coursera, or on some other platform?

It worked on Coursera.
Now I am running on my own computer.
Found a fix (thanks to meta.ai). Replaced the magic command with %matplotlib ipympl
Then had to install ipympl (pip install ipympl) and restarted the kernel. The error went away.

1 Like

Even “%matplotlib widget” works now.
So, looks like you just need to install ipympl.

Remember to restart kernel.

4 Likes