0

I have a problem with importing a module from a sub folder. I am running the main code from directory C:\Users\yeosiz\Desktop\bert_on_stilts. Folder glue is inside the mentioned directory and my main code is calling tasks.py inside the glue folder. I want to import get_taskand MnliMismatchedProcessor from tasks.py.

The structure of the directory:

bert_on_stilts
|_ main.py 
|_ glue
    |_tasks.py

Here is the code:

import sys
sys.path.insert(0, 'C:/Users/yeosiz/Desktop/bert_on_stilts/glue')
from glue.tasks import get_task, MnliMismatchedProcesso

But I get this error ModuleNotFoundError: No module named 'glue.tasks'. I am using python 3.6. Moreover, there is __init__ in the glue folder.

I have checked the following links to find the solution but I couldn't solve the problem Python 3 import class from subfolder problem, Import module from subfolder, and import main file (not another module) from a subfolder

LaurinO
  • 136
  • 6
Weiwei
  • 3
  • 2

2 Answers2

0

Just use:

from tasks import get_task, MnliMismatchedProcesso

or use:

sys.path.insert(0, 'C:/Users/yeosiz/Desktop/bert_on_stilts')

Otherwise, the glue is doubled.

LaurinO
  • 136
  • 6
0

you need to start the import with a relativity dot notation so it would be

from .glue.tasks import get_task, MnliMismatchedProcesso
karimkohel
  • 96
  • 1
  • 8