I am using lsp-pyright[1] module in doom Emacs for Python major mode. Local imports from my project are not recognized by lsp server.

I have created a pyrightconfig.json file in root directory of my folder but still issue is not resolved.

How to i tell lsp to read json config from my project root folder ?


You can include additional Python source paths with lsp-pyright-extra-paths. Here is my pyrightconfig.json for a project.

  "exclude": ["**/node_modules", "**/__pycache__"],
  "ignore": ["**/node_modules", "**/__pycache__"],
  "include": ["flextensor", "tvm"]
  "pythonPlatform": "Linux",
  "pythonVersion": "3.6",
  "reportMissingImports": true,
  "reportMissingTypeStubs": false,
  "stubPath": "typings",
  "typeCheckingMode": "basic",
  "venvPath": "/home/swarnendu/tmp/virtualenvs",
  "venv": "flextensor-venv"

Here is my Emacs setup (init.el) for pyright (ignoring remote Tramp setup). You could also use use-package for this.

  (when (executable-find "pyright")
    (unless (fboundp 'lsp-pyright-locate-python)
      (autoload #'lsp-pyright-locate-python "lsp-pyright" nil t))
    (unless (fboundp 'lsp-pyright-locate-venv)
      (autoload #'lsp-pyright-locate-venv "lsp-pyright" nil t))

    (add-hook 'python-mode-hook (lambda ()
                                  (require 'lsp-pyright)

    (defvar lsp-pyright-python-executable-cmd)
    (setq lsp-pyright-python-executable-cmd "python3")))

Here is the .dir-locals.el for the same project.

 (python-mode . (
                 (pyvenv-activate . "/home/swarnendu/tmp/virtualenvs/flextensor-venv")
                 (eval . (let (
                                (vconcat (list
                                          (expand-file-name "flextensor" (projectile-project-root))
                                          (expand-file-name "tvm" (projectile-project-root))
                           (setq lsp-pyright-extra-paths paths)))

Please check whether a similar setup works for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.