pythonvisual-studio-codepylancevscode-python

Pylance can't resolve the import of a library under same package


I am using VSCode and Pylance. I have the following workspace

- src
  - company
    - __init__.py
    - team
      - __init__.py
      - project
        - __init__.py
        - A.py
        - B.py

And I have some libraries that I import in A.py like this

from company.team import library1

since my workspace also contains company.team, Pylance tries to find library1 in my workspace.

If I do the following, pylance looks at the correct place (/lib/python3.8) and it works.

from company.team.library1 import foo

I have the correct path for python.autoComplete.extraPaths, so that is not an issue.

Any help?


Solution

  • Vscode is retrieved with the workspace as the root directory. You can use sys path. append().