Add docs on Python interpreter/env considerations#643
Add docs on Python interpreter/env considerations#643smheidrich wants to merge 2 commits intopython-lsp:developfrom
Conversation
| #### Example: NeoVim | ||
|
|
||
| For instance, if you use NeoVim's `vim.lsp` functions to set up the LSP configuration yourself, whether with your own config or a default one provided by [`nvim-lspconfig`](https://github.com/neovim/nvim-lspconfig), you can set/override the command it uses to launch `pylsp` like so: | ||
|
|
||
| ```vim | ||
| lua << EOF | ||
| vim.lsp.config('pylsp', { | ||
| -- Using the approach from Question 1, Option 4 to launch in an "overlay" venv | ||
| -- on top of the project's venv, if any (NeoVim takes care of sharing LSP servers | ||
| -- invocations between files in the same project): | ||
| cmd = { 'uv', 'run', '--with', 'python-lsp-server,pylsp-mypy', 'pylsp' }, | ||
| } | ||
| EOF | ||
| ``` | ||
|
|
||
| See [python-lsp-config#68 (comment)][issue-68-comment] for an example that doesn't use `uv` but tries to determine the project venv manually (e.g. for use with Question 1, Option 3). | ||
|
|
||
| [issue-68-comment]: https://github.com/python-lsp/python-lsp-server/pull/68#issuecomment-894650876 |
There was a problem hiding this comment.
You'll probably ask me to remove this part because it's editor-specific.
Not sure if there is a better way to demonstrate how to apply some of the advice in this document in a real configuration (or whether that should be done at all).
|
|
||
| ### Option 2 (better but still bad): In a global virtualenv specifically for `python-lsp-server` or your editor | ||
|
|
||
| This is better than the approach above, but won't help with plugins that need to run in your project's environment and don't have configuration variables to facilitate this. |
There was a problem hiding this comment.
Maybe this should be improved. Maybe there should be single configuration option for environment path and iti should be passed to all plugins?
Currently jedi accepts pylsp.plugins.jedi.environmet (and if needed also pylsp.plugins.jedi.extra_paths). I think this should be mentioned.
There was a problem hiding this comment.
Maybe this should be improved. Maybe there should be single configuration option for environment path and iti should be passed to all plugins?
Not all plugins would be able to respect this, or at least not fully - e.g. it wouldn't really help with Rope-based ones because you'd still have issues if your project's Python version doesn't match the one that pylsp is running in, because Rope uses the standard library's ast module to parse files, which is tied to that specific version.
Currently jedi accepts pylsp.plugins.jedi.environmet (and if needed also pylsp.plugins.jedi.extra_paths). I think this should be mentioned.
That the environment can be configured for Jedi-based plugins is mentioned in the plugin list near the start of the document. I didn't want to repeat the exact option names etc. to not make it needlessly long, but I did include a link to CONFIGURATION.md as a footnote in such cases.
Fixes #642.