0

I have looked at so many questions exactly like this but none of the solutions work its infuriating.

I want to call methods in a class in python that exist in a different module.

I have added init.py to each directory.

Structure:

  • server

    • database

      • __init.py
      • mongo.py
    • rabbit

      • _init_py
      • worker.py

In worker.py I import mongo as such:

from database import mongo

I then get the error 'No module named 'database' at runtime.

Please somebody explain, thanks!

jackabe
  • 345
  • 9
  • 23

1 Answers1

2
import sys
sys.path.append('../')
from database import mongo
Gokhan Gerdan
  • 1,222
  • 6
  • 19