ingrid
ingrid

Reputation: 107

Cannot import module in Jupyter Notebook (Python 3.6)

I want to import a user-defined module utils.py in Jupyter Notebook. This should be a trivial task, but for some reason it fails.

Project structure:

myapp/data/test.csv
myapp/packages/utils.py
myapp/test.ipynb

The file utils.py contains many functions, e.g. def myfunc():....

In test.ipynb I tried from packages import utils. Also I tried to put utils.py into the same folder as test.ipynb and run import utils. But all the time it fails with one of these two errors:

ImportError: cannot import name 'utils' ModuleNotFoundError: No module named 'utils'

The command sys.executable executed from the notebook gives me a correct path to python.exe.

It's weird because I can import data without any issues as follows:

df = pd.read_csv("data/test.csv", sep=";")

How can I check what causes this problem?

Upvotes: 0

Views: 2173

Answers (1)

Baron
Baron

Reputation: 106

Try this:

from packages.utils import *

It worked for me, so I hope it works for you aswell.

Upvotes: 1

Related Questions