简体   繁体   中英

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, eg 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?

Try this:

from packages.utils import *

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM