0

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?

2

1 Answer 1

1

Try this:

from packages.utils import *

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, but it gave me the same error "ModuleNotFoundError: No module named 'packages.utils". I think that there is some issue with sys.paths but I don't know how to validate it.
Have you tried to restart your kernel? It might not see the new import.
Importing with * works but I wonder why cannot I simply import by name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.