0

I have a Python project with nested modules:

root_dir:
   |-code_base
     |-task_code.py
     |-__init__.py
   |-utils_dir
     |-mysql_util.py
     |-__init__.py
   |-__init__.py

I'm using Visual Studio IDE and, loading the root_dir folder.

When i'm trying to import mysql_util file in tasks_code file, im getting Import Error. Import statement i'm using : from utils_dir.mysql_util import MySQLUtils

Error i'm receiving: ModuleNotFoundError: No module named 'utils_dir'

Please help me to resolve the issue.

2 Answers2

0

Before you import put in these two lines:

import sys
sys.path.append("../")

and then the import should work

user15270287
  • 1,123
  • 4
  • 11
0

Try relative explicit import:

from ..utils_dir.mysql_util import MySQLUtils
astrochun
  • 1,642
  • 2
  • 7
  • 18
  • Getting the following error. ImportError: attempted relative import with no known parent package – sai sri vatsava guntupalli Mar 02 '21 at 03:58
  • You'll need to add `root_dir` as a library/package. You can either do it by adding it to your PYTHONPATH env in your shell or use `sys.path` and append the full path of `root_dir` – astrochun Mar 02 '21 at 04:19