0

I have the following directory structure:

  • GNS
    • gns_export.py
  • new_structure
    • DB_Manager.py

and other Files that are not important. When I now try to import a function from DB_manager.py in gns_export.py, I get an error.

In gns_export.py: from new_structure.DB_Manager import *

Exception: ModuleNotFoundError: No module named 'new_structure'

  • Does this answer your question? [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time) – matszwecja Jul 06 '23 at 11:20

2 Answers2

0

Try the import with trailing dots:

https://docs.python.org/3/reference/import.html#package-relative-imports

0

If you're just importing the module and not running the file directly then @milchmannverleih's answer would work.

If for some reason you're trying to run it directly, then you can do it in the following way.

import os
import sys

sys.path.append(os.pardir)
from new_structure.DB_Manager import *

You can add your parent directory in the sys.path of the program and it'd be able to find new_structure folder there.

Zero
  • 1,807
  • 1
  • 6
  • 17