简体   繁体   English

Pylance 无法解析同一包下库的导入

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

I am using VSCode and Pylance.我正在使用 VSCode 和 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我有一些像这样在A.py中导入的库

from company.team import library1

since my workspace also contains company.team , Pylance tries to find library1 in my workspace.由于我的工作区还包含company.team ,因此library1尝试在我的工作区中查找 library1。

If I do the following, pylance looks at the correct place ( /lib/python3.8 ) and it works.如果我执行以下操作,pylance 会查看正确的位置( /lib/python3.8 )并且它可以工作。

from company.team.library1 import foo

I have the correct path for python.autoComplete.extraPaths , so that is not an issue.我有python.autoComplete.extraPaths的正确路径,所以这不是问题。

Any help?有什么帮助吗?

Vscode is retrieved with the workspace as the root directory.以工作空间为根目录检索 Vscode。 You can use sys path. append()您可以使用sys path. append() sys path. append() . sys path. append()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM