-1

I have the following folder structure in my project:

program
|-bin
   |-module1
      |-check.py
   |-module2
   |-module3
   |-functions.py
|-main.py

I am trying to get the modules located in bin/functions.py from bin/module1/check.py with this line:

from bin.functions import X

But for some reason the IDE tells me that it is fine but when I run the check.py it shows me the following error:

ModuleNotFoundError: No module named 'bin'

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Kevimuxx69
  • 109
  • 1
  • 7

1 Answers1

0

first thing you have to add blank __init__.py file in all folders.

Second thing you have to add path of program folder in sys.path

use below lines before import:

import os
import sys
path = os.path.join(os.path.dirname(__file__), "../../")
sys.path.insert(0, os.path.abspath(path))'
Amit Nanaware
  • 3,203
  • 1
  • 6
  • 19