Of lsp-mode which is the key to LSP in Spacemacs lsp-pyright allows you to use the Python type checker pyright I recently learned about it, so I use it
(There is a theory that the conventional pyls is fine, but recently I felt something heavy, so I'm trying pyrit, which has a reputation for being fast)
If you are using node, install pyright with npm
$ npm install -g pyright
In the layer setting of .spacemacs, it says to write like this, so write it.
It seems that it can be specified as an LSP server
.spacemacs(Excerpt)
(defun dotspacemacs/layers ()
  (setq-default
   dotspacemacs-configuration-layers
   '(
     (python :variables 
      python-backend 'lsp 
      python-lsp-server 'pyright)
    )
  )
)
cf. https://github.com/syl20bnr/spacemacs/tree/develop/layers/%2Blang/python
There seems to be no need to set up jedi on the Spacemacs side
When you open the Python file, you will be asked to decide the project root of LSP, but create pyrightconfig.json in the project root.
I did it on Ubuntu18.04LTS on WSL2 on Windows10, but if you put it in the project root v2project / with the user name v2okimochi, it looks like this
pyrightconfig.json
{
  "venvPath": "/home/v2okimochi/.local/share/virtualenvs/v2project-ABCDEFGH",
  "stubPath": "",
  "executionEnvironments": [
    {
      "root": "src"
    },
    {
      "root": "tests",
      "extraPaths": [
        "src"
      ]
    }
  ]
}
--Specify venvPath if you are using pipenv or pyenv
--It seems to be around .local/share/virtualenvs/ under the home directory
--This may also be useful [Use Spacemacs for Python auto-completion, linter, etc .-- Make Spacemacs recognize the python virtual environment](https://qiita.com/v2okimochi/items/db178969165e72d2032f#spacemacs%E3%81%A7python % E4% BB% AE% E6% 83% B3% E7% 92% B0% E5% A2% 83% E3% 82% 92% E8% AA% 8D% E8% AD% 98% E3% 81% 95% E3 % 81% 9B% E3% 82% 8B)
--Specify stubPath empty to eliminate unnecessary errors
--typings is not a valid directory I get an error and it's annoying (although it seems harmless)
cf. [typings.pyfile inside a project causes pyright to report that this is not a valid directory. ](https://github.com/microsoft/pyright/issues/777)  --Specify the root directory to be read by pyright  --The above example is when the project root hassrc /andtests / --If you do not specifysrc in tests / , you will not be able to refer to the source code of src / in the source code of tests / `.
When I tried to use boto3, I got an import unresolved error.
A similar error in VS Code seems to have been fixed. .. .. cf. all third party imports not resolved in VS Code
For the time being, I installed it secretly with pipenv run pip install boto3 and it solved it, but I feel something different (if it is written in the Pipfile but it is not installed, that is annoying)
Recommended Posts