GreySage
GreySage

Reputation: 1180

How can I get Jupyter Notebook to import a python file?

I have a very simple .py file, displayD3caller.py:

def caller():
    print("Here is a print statement from displayD3caller.py")

I can import and use the function defined in other files, and from the python shell. However, when I try to import the function in a Jupyter Notebook, it can't find the module:

ImportError: No module named 'displayD3caller'

What can I do to fix this?

Upvotes: 1

Views: 3974

Answers (1)

GreySage
GreySage

Reputation: 1180

Before Jupyter Notebook uses any change to the source code of related files, the kernal needs to be restarted. This includes creating a new file.

If you make a new module after Jupyter is already running, you need to restart the kernal before it will find it. From the top menu, select Kernal > Restart. You will need to re-execute any cells whose outputs you depend on.

Upvotes: 3

Related Questions