[Python] How to let pylsp find imports in local project?

Discussão em 'Python' iniciado por Stack, Novembro 27, 2025.

  1. Stack

    Stack Membro Participativo

    When starting my editor with pylsp inside a projects folder I can see the LSP root dir is chosen to be the top folder, where .git is. However the python code is located in a subfolder so the corresponding python imports are not understood by the lsp. (goto_definition results in "No location found").

    How can I make pylsp understand where my python code is?

    More details:

    The project structure is:

    .
    ├── .git
    ├── src
    │ ├── python
    │ │ ├── foo.py
    │ │ ├── app
    │ │ │ └── core.py
    │ └── lang2
    │ ├── bar.lang2
    │ └── settings.py
    ├── system
    ├── tests
    │ └── run.py
    └── util
    ├── examples
    │ └── example.py
    └── run.py


    after starting my editor I would like these imports to connect correctly into the src/python folder.

    import foo
    from app import core
    from app.core import Thing


    I use Neovim with python-lsp-server as my LSP. What are my options to fix this issue?

    I tried to launch it like this, but it had no obviuos affect:

    PYTHONPATH=src/python/ nvim


    The more general the solution, the better.

    Continue reading...

Compartilhe esta Página