Error when importing pylsp
I've searched open issues for similar requests
- [x] Yes
I've manually reviewed logs to find potential errors
- [x] Yes
I've recently downloaded the latest plugin version of mason.nvim
- [x] Yes
Problem description
As soon as a python file is open with nvim, with pylsp active for python and I have the following error.
[ERROR][2025-03-26 16:10:10] .../vim/lsp/rpc.lua:770 "rpc" "/home/home/.local/share/nvim/mason/bin/pylsp" "stderr" "2025-03-26 16:10:10,660 CET - ERROR - pylsp_jsonrpc.endpoint - Failed to handle request 1\nTraceback (most recent call last):\n File \"/home/home/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp_jsonrpc/endpoint.py\", line 117, in consume\n self._handle_request(message['id'], message['method'], message.get('params'))\n File \"/home/armando/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp_jsonrpc/endpoint.py\", line 197, in _handle_request\n handler_result = handler(params)\n ^^^^^^^^^^^^^^^\n File \"/home/armando/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp_jsonrpc/dispatchers.py\", line 25, in handler\n return method(**(params or {}))\n ^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/armando/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp/python_lsp.py\", line 326, in m_initialize\n self.config = config.Config(\n ^^^^^^^^^^^^^^\n File \"/home/armando/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp/config/config.py\", line 89, in __init__\n self._pm.load_setuptools_entrypoints(PYLSP)\n File \"/home/armando/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pluggy/_manager.py\", line 421, in load_setuptools_entrypoints\n plugin = ep.load()\n ^^^^^^^^^\n File \"/usr/lib/python3.11/importlib/metadata/__init__.py\", line 202, in load\n module = import_module(match.group('module'))\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/lib/python3.11/importlib/__init__.py\", line 126, in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"<frozen importlib._bootstrap>\", line 1206, in _gcd_import\n File \"<frozen importlib._bootstrap>\", line 1178, in _find_and_load\n File \"<frozen importlib._bootstrap>\", line 1142, in _find_and_load_unlocked\nModuleNotFoundError: No module named 'pylsp.plugins.rope_rename'\n"
Long story short, the file $HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp/plugins/rope_rename.py is missing.
Another example of the problem in stackoverflow
A quick fix, is to create it (and the error is gone).
touch $HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp/plugins/rope_rename.py
I do not really know lsp, mason or how any of this works hence I do not know if the issue is mason one, pylsp or other...
The only thing I did find out and may help to solve the issue is that the new repository python-lsp-server, does not have the rope_name.py file.
Nevertheless, there is an old palantir repository which do contains the file.
Mason registry and nvim-lspconfig both have the new referenced.
Expected behavior
Not to have the error mentioned above.
Steps to reproduce
Open a python file with neovim.
Affected packages
pylsp
Neovim version (>= 0.7)
Neovim 0.10.2 Mason up to date through LazyVim.
Operating system/version
Linux 6.1.0-32-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.129-1 (2025-03-06) x86_64 GNU/Linux
Healthcheck
==============================================================================
mason: require("mason.health").check()
mason.nvim ~
- OK mason.nvim version v1.11.0
- OK PATH: prepend
- OK Providers:
mason.providers.registry-api
mason.providers.client
- OK neovim version >= 0.7.0
mason.nvim [Registries] ~
- OK Registry `github.com/mason-org/mason-registry version: 2025-03-26-frozen-elver` is installed.
mason.nvim [Core utils] ~
- OK unzip: `UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.`
- OK wget: `GNU Wget 1.21.3 built on linux-gnu.`
- OK curl: `curl 7.88.1 (x86_64-pc-linux-gnu) libcurl/7.88.1 OpenSSL/3.0.15 zlib/1.2.13 brotli/1.0.9 zstd/1.5.4 libidn2/2.3.3 libpsl/0.21.2 (+libidn2/2.3.3) libssh2/1.10.0 nghttp2/1.52.0 librtmp/2.3 OpenLDAP/2.5.13`
- OK gzip: `gzip 1.12`
- OK tar: `tar (GNU tar) 1.34`
- OK bash: `GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)`
- OK sh: `Ok`
mason.nvim [Languages] ~
- WARNING luarocks: not available
- ADVICE:
- spawn: luarocks failed with exit code - and signal -. luarocks is not executable
- OK Go: `go version go1.23.3 linux/amd64`
- OK Ruby: `ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu]`
- OK cargo: `cargo 1.83.0 (5ffbef321 2024-10-29)`
- OK PHP: `PHP 8.2.28 (cli) (built: Mar 13 2025 18:21:38) (NTS)`
- OK node: `v18.19.0`
- OK RubyGem: `3.3.15`
- WARNING julia: not available
- ADVICE:
- spawn: julia failed with exit code - and signal -. julia is not executable
- OK python: `Python 3.11.2`
- OK Composer: `Composer version 2.5.5 2023-03-21 11:50:05`
- OK java: `openjdk version "17.0.14" 2025-01-21`
- OK javac: `javac 17.0.14`
- OK pip: `pip 23.0.1 from /usr/lib/python3/dist-packages/pip (python 3.11)`
- OK python venv: `Ok`
- OK npm: `9.2.0`
mason.nvim [GitHub] ~
- OK GitHub API rate limit. Used: 1. Remaining: 59. Limit: 60. Reset: Wed 26 Mar 2025 18:50:37 CET.
Install and authenticate via gh-cli to increase rate limit.
Screenshots or recordings
No response
Same on Debian 12 with NVIM v0.10.4 and Mason 1.11.0 and mason-lspconfig 1.32.0
Strangely, when I open a python shell in some terminal, I can do import pylsp.plugins.rope_rename, and this works fine. I've not created any rope_rename.py file before testing. I wasn't in the venv either. ($HOME/.local/share/nvim/mason/packages/python-lsp-server/venv)
I've just formatted the error message here:
Traceback (most recent call last):
File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp_jsonrpc/endpoint.py", line 117, in consume
self._handle_request(message['id'], message['method'], message.get('params'))
File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp_jsonrpc/endpoint.py", line 197, in _handle_request
handler_result = handler(params)
^^^^^^^^^^^^^^^
File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp_jsonrpc/dispatchers.py", line 25, in handler
return method(**(params or {}))
^^^^^^^^^^^^^^^^^^^^^^^^
File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp/python_lsp.py", line 326, in m_initialize
self.config = config.Config(
^^^^^^^^^^^^^^
File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp/config/config.py", line 89, in __init__
self._pm.load_setuptools_entrypoints(PYLSP)
File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pluggy/_manager.py", line 421, in load_setuptools_entrypoints
plugin = ep.load()
^^^^^^^^^
File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/importlib_metadata/__init__.py", line 189, in load
module = import_module(match.group('module'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pylsp.plugins.rope_rename'
This python error message was inside the data block below:
Error executing vim.schedule lua callback:
...nvimL3OaY1/usr/share/nvim/runtime/lua/vim/lsp/client.lua:588: RPC[Error] code_name = InvalidParams, message = "ModuleNotFoundError: No module named 'pylsp.plugins.rope_rename'" data = { PYTHON ERROR }
stack traceback:
[C]: in function 'assert'
...nvimL3OaY1/usr/share/nvim/runtime/lua/vim/lsp/client.lua:588: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
When pylsp is loaded, neovim could find all the plugins for it except rope_rename, and thus this error occurs. It tries to access the plugins from this directory
~/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp/plugins
However, this directory contains every plugin file except rope_rename.py, which is instead located in this directory:
~/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pyls/plugins
copy pasting the file to the required location solved the issue for me.
According to https://github.com/python-lsp/python-lsp-server/pull/515 the rope_rename was replaced by the pylsp-rope plugin. I don't know whether this is a mason issue or pylsp issue but it seems some files are still trying to access pylsp.plugins.rope_rename after the change.