How do I fix "Import 'file_name' couldn't be resolved by pylance" problem?

497 views Asked by At

This is the code:

from .packages import six 
from .packages.six.moves.http_client import HTTPConnection as _HTTPConnection
from .packages.six.moves.http_client import HTTPException  # noqa: F401

And the problem Import ".packages.six.moves.http_client" could not be resolved Pylance is raised at line 2 & 3.

Similar post that I found on this website is: Cannot import HTTPConnection from six.moves.http_client however I couldn't follow along with the answer given there.

Edit:1 Furthermore, When I run the file, ImportError: attempted relative import with no known parent package is raised at line from .packages import six in above code.

Edit:2 This webpage: https://techwithtech.com/importerror-attempted-relative-import-with-no-known-parent-package/ clearly explains the ImportError mentioned in Edit:1 but I am unable to fix it. So What am I missing here?

The file structure of connection.py and six.py are underlined in the picture below.

The files are underlined where as the code is wrapped in bracket

0

There are 0 answers