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?

ingrid
  • 107
  • 1
  • 6

1 Answers1

1

Try this:

from packages.utils import *

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

Baron
  • 106
  • 1
  • 10
  • 1
    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. – ingrid Jan 09 '19 at 11:17
  • Have you tried to restart your kernel? It might not see the new import. – Baron Jan 09 '19 at 11:21
  • Importing with * works but I wonder why cannot I simply import by name – meliksahturker Sep 09 '21 at 18:45