Search code examples
pythonpython-modulerelative-import

Relative import of python module from current working directory


In the current working directory , i have following structure

Project
   __init__.py
   -RestApi
           __init__.py
           app.py
           query_generator
   -testfolder
           __init__.py
           test1.py

I want to call query_generator from test1.py , I tried calling

 from . RestApi.query_generator import *

but getting following error

ImportError: attempted relative import with no known parent package

This question might be duplicate of following Importing files from different folder , Python relative-import script two levels up, Attempted relative import with no known parent package . But I am not able to solve it for my current problem


Solution

  • Try using below import:

    from Project.RestApi.query_generator import *