LSP-pylsp
Convenience package for the Python Language Server
Details
Installs
- Total 22K
- Win 10K
- Mac 5K
- Linux 7K
| Oct 28 | Oct 27 | Oct 26 | Oct 25 | Oct 24 | Oct 23 | Oct 22 | Oct 21 | Oct 20 | Oct 19 | Oct 18 | Oct 17 | Oct 16 | Oct 15 | Oct 14 | Oct 13 | Oct 12 | Oct 11 | Oct 10 | Oct 9 | Oct 8 | Oct 7 | Oct 6 | Oct 5 | Oct 4 | Oct 3 | Oct 2 | Oct 1 | Sep 30 | Sep 29 | Sep 28 | Sep 27 | Sep 26 | Sep 25 | Sep 24 | Sep 23 | Sep 22 | Sep 21 | Sep 20 | Sep 19 | Sep 18 | Sep 17 | Sep 16 | Sep 15 | Sep 14 | Sep 13 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Windows | 6 | 3 | 6 | 6 | 3 | 8 | 16 | 2 | 4 | 4 | 2 | 5 | 9 | 3 | 8 | 6 | 8 | 8 | 14 | 3 | 4 | 5 | 4 | 4 | 3 | 14 | 12 | 7 | 10 | 5 | 10 | 5 | 4 | 7 | 8 | 8 | 9 | 2 | 3 | 6 | 4 | 4 | 8 | 6 | 2 | 9 |
| Mac | 3 | 2 | 2 | 2 | 3 | 4 | 3 | 4 | 3 | 0 | 1 | 6 | 3 | 2 | 3 | 3 | 1 | 3 | 3 | 2 | 3 | 1 | 1 | 3 | 1 | 3 | 1 | 1 | 2 | 1 | 1 | 2 | 5 | 2 | 6 | 3 | 4 | 2 | 5 | 4 | 4 | 2 | 7 | 3 | 6 | 1 |
| Linux | 8 | 9 | 3 | 9 | 4 | 14 | 5 | 3 | 5 | 10 | 7 | 9 | 4 | 7 | 6 | 6 | 9 | 4 | 3 | 12 | 9 | 12 | 7 | 3 | 4 | 3 | 6 | 7 | 6 | 6 | 7 | 7 | 3 | 5 | 9 | 10 | 12 | 2 | 4 | 6 | 5 | 8 | 3 | 7 | 9 | 3 |
Readme
- Source
- raw.githubusercontent.com
LSP-pylsp
This is a helper package that automatically installs and updates the Python LSP Server (pylsp) for you.
To use this package, you must have:
- An executable
python(on Windows) orpython3(on Linux/macOS) - The LSP package
- For Ubuntu and Debian users, you must also install
python3-venvwithapt - It's recommended to also install the
LSP-jsonpackage which will provide auto-completion and validation for this package's settings.
Applicable Selectors
This language server operates on views with the source.python base scope.
Installation Location
The server is installed in the $CACHE/Package Storage/LSP-pylsp directory, where $CACHE is the base data path of Sublime Text.
For instance, $CACHE is ~/.cache/sublime-text on a Linux system. If you want to force a re-installation of the server,
you can delete the entire $CACHE/Package Storage/LSP-pylsp directory or just reinstall the package. The installation is done through a virtual environment, using
pip. Therefore, you must have at least the python executable installed and it must be present in your $PATH.
Like any helper package, installation starts when you open a view that is suitable for this language server. In this
case, that means that when you open a view with the source.python base scope, installation commences.
Running alongside LSP-pyright
LSP-pyright is a more modern, faster and actively supported alternative to LSP-pylsp. While it's arguably much better solution for validating the code and type-checking, it doesn't support linters or code formatters like flake8, pyflakes, pydocstyle, yapf or black. The solution to that could be to run them alongside each other with code-checking features disabled in LSP-pylsp. To achieve that, open Preferences: LSP-pylsp Settings from the Command Palette and add the following user settings:
{
"disabled_capabilities": {
"completionProvider": true,
"definitionProvider": true,
"documentHighlightProvider": true,
"documentSymbolProvider": true,
"hoverProvider": true,
"referencesProvider": true,
"renameProvider": true,
"signatureHelpProvider": true,
},
"settings": {
"pylsp.plugins.jedi_completion.enabled": false,
"pylsp.plugins.jedi_definition.enabled": false,
"pylsp.plugins.jedi_hover.enabled": false,
"pylsp.plugins.jedi_references.enabled": false,
"pylsp.plugins.jedi_signature_help.enabled": false,
"pylsp.plugins.jedi_symbols.enabled": false,
},
}
Configuration
Configure the Python LSP Server by accessing Preferences > Package Settings > LSP > Servers > LSP-pylsp.
Python Binary
The underlying pylsp server will be installed inside a virtual environment created using a system-default Python interpreter (by default python on Windows and python3 on other platforms). If you want to, for example, develop code that requires a newer version of Python than the one installed by default, you can override the path to the Python interpreter (binary) by changing the python_binary setting. For example:
// Settings in here override those in "LSP-pylsp/LSP-pylsp.sublime-settings"
{
"python_binary": "/opt/homebrew/bin/python3",
}
Virtual environments
If your project needs to run and be validated within a virtual environment, point to the environment using the pylsp.plugins.jedi.environment setting. For example, if your virtual environment lives in .venv/myproject within the project directory then run Project: Edit Project from the Command Palette and add the setting like so:
{
// "folders": [
// ...
// ]
"settings":
{
"LSP":
{
"LSP-pylsp":
{
"settings":
{
"pylsp.plugins.jedi.environment": "./.venv/myproject"
}
}
}
}
}
You can also set it in the LSP-pylsp global settings but it's more likely that you'd want this to be overridden per-project.
Code Completion
This language server provides code completion through JEDI.
Signature Help
This language server provides signature help through JEDI.
Goto
This language server provides “goto definition” through JEDI.
Find References
This language server provides “find references” through JEDI.
Rename
This language server provides “rename word/symbol” through JEDI.
Linters
The default linter is pycodestyle. The possible linters are:
- pycodestyle (
"pylsp.plugins.pycodestyle.enabled"in the settings) - pydocstyle (
"pylsp.plugins.pydocstyle.enabled"in the settings) - flake8 (
"pylsp.plugins.flake8.enabled"in the settings) For flake8 to work, you must also modify"pylsp.configurationSources"to be["flake8"]instead of the default["pycodestyle"]. - pyflakes (
"pylsp.plugins.pyflakes.enabled"in the settings) - pylint (
"pylsp.plugins.pylint.enabled"in the settings) - pylsp_mypy (
"pylsp.plugins.pylsp_mypy.enabled"in the settings) - ruff (
"pylsp.plugins.ruff.enabled"in the settings)
After changing a linter, you must restart Sublime Text.
Formatters
The default formatter is autopep8. The possible formatters are:
| Name | Setting | Note |
|---|---|---|
| autopep8 | pylsp.plugins.autopep8.enabled |
|
| black | pylsp.plugins.black.enabled |
When enabling also make sure that autopep8 and yapf are disabled. |
| ruff | pylsp.plugins.ruff.formatEnabled |
Make sure to also enable pylsp.plugins.ruff.enabled and disable other formatters and linters. |
| yapf | pylsp.plugins.yapf.enabled |
Sorting import statements
To sort your import statements, you can enable isort. The relevant setting is "pylsp.plugins.pyls_isort.enabled" in
the settings. Sorting is done through the “LSP: Format Document” option in the Context Menu by right-clicking within the
view with your mouse.
Sublime Text Plugin Development
By default, the environment of pylsp is adjusted so that the PYTHONPATH includes the directory where sublime.py and
sublime_plugin.py live, as well as the $DATA/Packages directory. This enables accurate code completion for these
files.