Miguel GC
Miguel GC

Reputation: 63

Python 3 with Jupyter notebook: Cannot import file in the same directory

I am using Python 3 on Windows 10 within a Jupyter notebook. I have two files in the same directory, Test1.py and Test2.py

In Test1 I have:

def method1():
print ("Hello World!")

And in Test2 I have:

from Test1 import method1

But when running Test2 I get the error:

No module named 'Test1'

I know this question has been asked before, so I tried the main suggestion: add the current directory to sys.path:

import sys
sys.path.append('/path/to/Test1')

However, this solution does not work for me and I still get the same error. Thank you for your help!

Upvotes: 1

Views: 534

Answers (1)

Kei H
Kei H

Reputation: 100

I think you should put a __init__.py in your directory which have Test1.py and Test2.py.

Upvotes: 2

Related Questions