[Python] pylance does not recognize local packages installed with "pip install -e "

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following project setup (names changed):

    ProjectRoot
    │
    ├───DependencyPackage
    │ │ .gitignore
    │ │ Dockerfile
    │ │ LICENSE
    │ │ pyproject.toml
    │ │ README.md
    │ │ setup.cfg
    │ │ setup.py
    │ │
    │ └───dependency_source
    │ │ __init__.py
    │ │
    │ ├───models
    │ │ first_model.py
    │ │ second_model.py
    │ │
    │ └───code
    │ some_logic.py
    │
    ├───MainPackage
    │ │ .gitignore
    │ │ Dockerfile
    │ │ LICENSE
    │ │ pyproject.toml
    │ │ README.md
    │ │ setup.cfg
    │ │ setup.py
    │ │
    │ │
    │ └───main_source
    │ main.py
    │ __init__.py
    │
    └───venv


    In Visual Studio Code the interpreter is chosen via path to venv/Scripts/python.exe, both MainPackage as well as DependencyPackage are installed in the virtual environment via pip install -e ".[dev]", they also show up with the correct path and version in pip list

    The dependency package is listed as install_requires = dependency_package and I have checked all the naming (e.g. - vs _) several times.

    Additionally the code runs fine if I for example use in the MainPackage/main_source/main.py:

    from dependency_package.code.some_logic import myfunction

    def main():
    myfunction("something something...")

    if __name__ == "__main__":
    main()


    However, even though everything clearly works (?), I still get the following pylance error on import:


    Import "dependency_package.code.some_logic" could not be resolved and Intellisense fails and I get no code completion suggestions and so on...
    ​

    Clearly I am missing something here.

    addition: Just tested again, installing with pip install (no -e), will work fine and my imports are recognized. I do however need the -e flag, since I am developing on both packages simultaneously.

    Continue reading...

Compartilhe esta Página