0

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?

4
  • Use absolute path Commented May 24, 2022 at 3:05
  • My use case is perfectly valid and I'd rather not use hacky solutions just to appease pylance. Commented May 24, 2022 at 10:43
  • 1
    I'm sorry to reply to you after such a long time. Vscode is retrieved with the workspace as the root directory. You can use "sys path. append()". Commented Jun 6, 2022 at 1:10
  • I came to the same conclusion recently. Thanks. Commented Jul 5, 2022 at 14:08

2 Answers 2

1

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

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

Comments

0

Try add "python.analysis.includeAliasesFromUserFiles": true on your settings.json, as per https://code.visualstudio.com/docs/python/settings-reference#:~:text=includeAliasesFromUserFiles it will:

"include alias symbols from user files in auto-import suggestions and in the add import Quick Fix"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.