NameError: name 'IN_NOTEBOOK' is not defined


I’m trying to set up the notebooks and run the code in 01_intro, but I’ve been hit with the same error on two different platforms.

If I try to run the first cell:

!pip install -Uqq fastbook
import fastbook

I get a NameError: name ‘IN_NOTEBOOK’ is not defined. I get this error on gradient and in DataCrunch. Is there something I’m not setting up properly, or has anyone had any similar problems?

Any help would be greatly appreciated, as I feel like I’m missing something obvious. Thankyou in advance!



I am also having the same problem, I just made the environment and updated according to,

I think is due to some recent commit in their git or a mistake in the library fastbook or fastai.

I will try resetting my paperspace machine and return if the error is solved

More details on the problem:

1 #hide
----> 2 from utils import *

/notebooks/course-v4/nbs/ in
1 # Numpy and pandas by default assume a narrow screen - this fixes that
2 from import *
----> 3 from nbdev.showdoc import *
4 from ipywidgets import widgets
5 from pandas.api.types import CategoricalDtype

/opt/conda/envs/fastai/lib/python3.8/site-packages/nbdev/ in
6 from .flags import *
----> 7 from .showdoc import show_doc
8 #from .export import notebook2script

/opt/conda/envs/fastai/lib/python3.8/site-packages/nbdev/ in
12 from nbconvert import HTMLExporter
—> 14 if IN_NOTEBOOK:
15 from IPython.display import Markdown,display
16 from IPython.core import page

NameError: name ‘IN_NOTEBOOK’ is not defined

I think I fixed the problem by running in terminal:

pip install nbdev --upgrade

then shutdown the notebook if running and re-open.


Thankyou so much! This seemed to work for me great!

Worked for me too! thanks!

Thank-you, that’s happened a couple of times now with DataCrunch too, and that process worked. I started the terminal and used the pip install nbdev --upgrade . Re-tried without shutting down the notebook, and it failed, but once I shutdown the notebook and restarted, it all worked. Many thanks.

1 Like

I am very happy that I managed to help some people! You guys are wonderful :slight_smile:


thank you I was having the same issue and this is the fix.

Thanks, this got the issue fixed :+1:t2:

Thanks, this worked for me!

Thanks, this worked for me as well!

This did not work for me.

Updated to fastai/fastbook (using clean version)
Ran terminal pip install nbdev --upgrade
Ran terminal pip install fastai fastcore --upgrade
Shutdown notebook and re-open
(And even tried running the notebook instance again)

I still get
try: from nbdev.showdoc import *
17 except ModuleNotFoundError: warn(“Missing nbdev - please install it”)
18 try:

Try changing the order in which you run the terminal commands.
I guess pip install nbdev --upgrade should come second, after you ran pip install fastai fastcore --upgrade first

try this article, it worked for me. it teaches how to setup in jupyter. all u need to do by yourself is start the geadient notebook, please respond if you have any issues, i will be checking my acccount regularly. if u cannot view it from the link, head to twqittwer and send this link as a amessage to yourself and open it from the twitter inbox … cheers

I don’t know if this is a legit fix but I fixed it by editing and adding these two lines:


@LucasM Just created an account to let you know that this helped. Much thanks.

1 Like