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

2 Answers 2

0

Before you import put in these two lines:

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

and then the import should work

Sign up to request clarification or add additional context in comments.

Comments

0

Try relative explicit import:

from ..utils_dir.mysql_util import MySQLUtils

2 Comments

Getting the following error. ImportError: attempted relative import with no known parent package
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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.