-1

I was having some problem when trying to import method from another python class. I am following this guide. When I tried to run the attention.py, I am getting this error message:

File "D:\Desktop\tensorrec-master\examples\attention_example.py", line 8, in <module>
from test.datasets import get_movielens_100k
ModuleNotFoundError: No module named 'test.datasets'

I even tried to change the import statement to:

import test.datasets.py
test.datasets.get_movielens_100k(negative_value=0)

But I am still getting the same error message. Any ideas? Thanks!

QWERTY
  • 2,303
  • 9
  • 44
  • 85

2 Answers2

1

Project structure needs to be known to your Python interpreter. And how to do it?

Set PYTHONPATH to base directory of your project Add init.py file in each directory

Voila! You will be able to import from any directory under your base folder after that

Priyank Mehta
  • 2,453
  • 2
  • 21
  • 32
1

From Import a file from a subdirectory? :

In short, you need to put a blank file named

__init__.py

in the "lib" directory.

Toivo Mattila
  • 377
  • 1
  • 9