python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.94k stars 194 forks source link

How to handle "ModuleNotFoundError: No module named 'pylsp.plugins.rope_rename'" #588

Open buhtz opened 2 months ago

buhtz commented 2 months ago

Hello,

I was updating all my Emacs (29 from Debian 12 backports) packages after a while and no got this error. After doing some research it seems that rope-support was removed from pylsp.

[eglot] (warning) [eglot] -32602: ModuleNotFoundError: No module named 'pylsp.plugins.rope_rename'

I installed it explicit via pip install -U pylsp-rope but nothing changed. OK, I am also fine with just disabling rope in my setup. But I don't know how. I don't see "rope" in my init.el.

My (reduced) init.el is ~240 lines long. Not sure if it make sense to post it here.

Any suggestion how to go further with analyzing this?

ghost-in-the-zsh commented 2 months ago

I encountered this pylsp crash after a recent nvim "!Lazy sync" ... command, even after updating everything else. The LSP stacktrace I got is below, pretty-fied and with my home path replaced by $HOME. This is a hard crash that prevents the LSP from launching and attaching to the buffer. Are there any suggested workarounds while a fix is released? :thinking:

Error executing vim.schedule lua callback: .../nvim/2823/usr/share/nvim/runtime/lua/vim/lsp/client.lua:589: RPC[Error] code_name = InvalidParams, message = "ModuleNotFoundError: No module named 'pylsp.plugins.rope_rename'" data = {
  traceback = {
    "  File \"$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp_jsonrpc/endpoint.py\", line 117, in consume\n   self._handle_request(message['id'], message['method'], message.get('params'))\n",
    '  File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp_jsonrpc/endpoint.py", line 197, in _handle_request\n    handler_result = handler(params)\n  ^^^^^^^^^^^^^^^\n',
    '  File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp_jsonrpc/dispatchers.py", line 25, in handler\n    return method(**(params or {}))\n           ^^^^^^^^^^^^^^^^^^^^^^^^\n',
    '  File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp/python_lsp.py", line 326, in m_initialize\n    self.config = config.Config(\n                  ^^^^^^^^^^^^^^\n',
    '  File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp/config/config.py", line 89, in __init__\n    self._pm.load_setuptools_entrypoints(PYLSP)\n',
    '  File "$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_manager.py", line 421, in load_setuptools_entrypoints\n    plugin = ep.load()\n             ^^^^^^^^^\n',
    "  File \"$HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/importlib_metadata/__init__.py\", line 183, in load\n    module = import_module(match.group('module'))\n         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
    '  File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module\n    return _bootstrap._gcd_import(name[level:], package, level)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n',
    '  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import\n',
    '  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load\n',
    '  File "<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked\n'
  }
}
stack traceback:
        [C]: in function 'assert'
        .../nvim/2823/usr/share/nvim/runtime/lua/vim/lsp/client.lua:589: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
php1ic commented 2 months ago

I'm having the same issue with neovim after a recent update of packages and lsp servers on my system. Could this be related to #515?

dcherian commented 2 months ago

Here is a traceback that might help

[stderr]  2024-08-30 09:37:12,221 MDT - ERROR - pylsp_jsonrpc.endpoint - Failed to handle request 1
[stderr]  Traceback (most recent call last):
[stderr]    File "/Users/deepak/miniforge3/lib/python3.11/site-packages/pylsp_jsonrpc/endpoint.py", line 117, in consume
[stderr]      self._handle_request(message['id'], message['method'], message.get('params'))
[stderr]    File "/Users/deepak/miniforge3/lib/python3.11/site-packages/pylsp_jsonrpc/endpoint.py", line 197, in _handle_request
[stderr]      handler_result = handler(params)
[stderr]                       ^^^^^^^^^^^^^^^
[stderr]    File "/Users/deepak/miniforge3/lib/python3.11/site-packages/pylsp_jsonrpc/dispatchers.py", line 25, in handler
[stderr]      return method(**(params or {}))
[stderr]             ^^^^^^^^^^^^^^^^^^^^^^^^
[stderr]    File "/Users/deepak/miniforge3/lib/python3.11/site-packages/pylsp/python_lsp.py", line 326, in m_initialize
[stderr]      self.config = config.Config(
[stderr]                    ^^^^^^^^^^^^^^
[stderr]    File "/Users/deepak/miniforge3/lib/python3.11/site-packages/pylsp/config/config.py", line 89, in __init__
[stderr]      self._pm.load_setuptools_entrypoints(PYLSP)
[stderr]    File "/Users/deepak/miniforge3/lib/python3.11/site-packages/pluggy/_manager.py", line 421, in load_setuptools_entrypoints
[stderr]      plugin = ep.load()
[stderr]               ^^^^^^^^^
[stderr]    File "/Users/deepak/miniforge3/lib/python3.11/site-packages/importlib_metadata/__init__.py", line 183, in load
[stderr]      module = import_module(match.group('module'))
[stderr]               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[stderr]    File "/Users/deepak/miniforge3/lib/python3.11/importlib/__init__.py", line 126, in import_module
[stderr]      return _bootstrap._gcd_import(name[level:], package, level)
[stderr]             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[stderr]    File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
[stderr]    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
[stderr]    File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
[stderr]  ModuleNotFoundError: No module named 'pylsp.plugins.rope_rename'

magically, just adding an empty rope_rename.py in plugins/ makes it all work

php1ic commented 2 months ago

Adding the file works for me. Thanks @dcherian!

ghost-in-the-zsh commented 2 months ago

The issue seems to have been resolved. I updated yesterday, without manually adding any files, and I no longer see the error.

php1ic commented 2 months ago

Strange, I still see the error if I remove the rope_rename.py file.

What did you update? I've got all the latest updates for packages installed via Lazy and I use Mason for my LSP servers and that is still showing 1.12.0 for python-lsp-server with no available updates.

ghost-in-the-zsh commented 2 months ago

Strange, I still see the error if I remove the rope_rename.py file.

What did you update? I've got all the latest updates for packages installed via Lazy and I use Mason for my LSP servers and that is still showing 1.12.0 for python-lsp-server with no available updates.

I stand corrected... after updating this morning, I now see the crash again, but it was definitely not broken when I posted last time. Someone seems to keep messing up and there's no official response in this thread, either...

BTW, if anyone's wondering where, exactly, you should touch rope_rename.py, it should be under $HOME/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/<your-python-version>/site-packages/pylsp/plugins/