EeyoreLee / vscode-extension-yapf

Vscode formatter extension support for python files using `yapf`.
MIT License
18 stars 5 forks source link

ModuleNotFoundError: No module named 'lsp_jsonrpc' #181

Closed xiaomoy closed 1 month ago

xiaomoy commented 1 month ago
2024-10-13 00:02:41.433 [info] Name: yapf
2024-10-13 00:02:41.433 [info] Module: yapf
2024-10-13 00:02:41.433 [info] Python extension loading
2024-10-13 00:02:41.433 [info] Waiting for interpreter from python extension.
2024-10-13 00:02:41.433 [info] Python extension loaded
2024-10-13 00:02:41.433 [info] Server run command: d:\Portables\python-3.13.0-embed-amd64\python.exe c:\Users\1\.vscode\extensions\eeyore.yapf-2024.9.126091437\bundled\tool\lsp_server.py
2024-10-13 00:02:41.433 [info] Server: Start requested.
2024-10-13 00:02:41.491 [info] Traceback (most recent call last):

2024-10-13 00:02:41.491 [info]   File "c:\Users\1\.vscode\extensions\eeyore.yapf-2024.9.126091437\bundled\tool\lsp_server.py", line 44, in <module>
    import lsp_jsonrpc as jsonrpc
ModuleNotFoundError: No module named 'lsp_jsonrpc'

2024-10-13 00:02:41.496 [info] [Error - 00:02:41] Server initialization failed.
2024-10-13 00:02:41.496 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.496 [info] [Info  - 00:02:41] Connection to server got closed. Server will restart.
2024-10-13 00:02:41.496 [info] true
2024-10-13 00:02:41.496 [info] [Error - 00:02:41] yapf client: couldn't create connection to server.
2024-10-13 00:02:41.496 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.563 [info] Traceback (most recent call last):

2024-10-13 00:02:41.563 [info]   File "c:\Users\1\.vscode\extensions\eeyore.yapf-2024.9.126091437\bundled\tool\lsp_server.py", line 44, in <module>
    import lsp_jsonrpc as jsonrpc
ModuleNotFoundError: No module named 'lsp_jsonrpc'

2024-10-13 00:02:41.568 [info] [Error - 00:02:41] Server initialization failed.
2024-10-13 00:02:41.568 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.568 [info] [Info  - 00:02:41] Connection to server got closed. Server will restart.
2024-10-13 00:02:41.568 [info] true
2024-10-13 00:02:41.569 [info] [Error - 00:02:41] yapf client: couldn't create connection to server.
2024-10-13 00:02:41.569 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.569 [error] Server: Start failed: Error: Pending response rejected since connection got disposed
2024-10-13 00:02:41.630 [info] Traceback (most recent call last):

2024-10-13 00:02:41.630 [info]   File "c:\Users\1\.vscode\extensions\eeyore.yapf-2024.9.126091437\bundled\tool\lsp_server.py", line 44, in <module>
    import lsp_jsonrpc as jsonrpc
ModuleNotFoundError: No module named 'lsp_jsonrpc'

2024-10-13 00:02:41.635 [info] [Error - 00:02:41] Server initialization failed.
2024-10-13 00:02:41.635 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.635 [info] [Info  - 00:02:41] Connection to server got closed. Server will restart.
2024-10-13 00:02:41.635 [info] true
2024-10-13 00:02:41.635 [info] [Error - 00:02:41] yapf client: couldn't create connection to server.
2024-10-13 00:02:41.635 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.635 [info] [Error - 00:02:41] Restarting server failed
2024-10-13 00:02:41.635 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.695 [info] Traceback (most recent call last):

2024-10-13 00:02:41.695 [info]   File "c:\Users\1\.vscode\extensions\eeyore.yapf-2024.9.126091437\bundled\tool\lsp_server.py", line 44, in <module>
    import lsp_jsonrpc as jsonrpc
ModuleNotFoundError: No module named 'lsp_jsonrpc'

2024-10-13 00:02:41.700 [info] [Error - 00:02:41] Server initialization failed.
2024-10-13 00:02:41.700 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.700 [info] [Info  - 00:02:41] Connection to server got closed. Server will restart.
2024-10-13 00:02:41.700 [info] true
2024-10-13 00:02:41.700 [info] [Error - 00:02:41] yapf client: couldn't create connection to server.
2024-10-13 00:02:41.700 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.700 [info] [Error - 00:02:41] Restarting server failed
2024-10-13 00:02:41.700 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.759 [info] Traceback (most recent call last):

2024-10-13 00:02:41.759 [info]   File "c:\Users\1\.vscode\extensions\eeyore.yapf-2024.9.126091437\bundled\tool\lsp_server.py", line 44, in <module>
    import lsp_jsonrpc as jsonrpc
ModuleNotFoundError: No module named 'lsp_jsonrpc'

2024-10-13 00:02:41.764 [info] [Error - 00:02:41] Server initialization failed.
2024-10-13 00:02:41.764 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.764 [info] [Error - 00:02:41] The yapf server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
2024-10-13 00:02:41.764 [info] [Error - 00:02:41] yapf client: couldn't create connection to server.
2024-10-13 00:02:41.764 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-10-13 00:02:41.764 [info] [Error - 00:02:41] Restarting server failed
2024-10-13 00:02:41.764 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
EeyoreLee commented 1 month ago

@xiaomoy - hi, I test it on python=3.13 but works fine on my side. Could you check whether lsp_jsonrpc.py on c:\Users\1\.vscode\extensions\eeyore.yapf-2024.9.126091437\bundled\tool floder? You can reinstall this extension if lsp_jsonrpc.py not exists.

xiaomoy commented 1 month ago

@xiaomoy - hi, I test it on python=3.13 but works fine on my side. Could you check whether lsp_jsonrpc.py on c:\Users\1\.vscode\extensions\eeyore.yapf-2024.9.126091437\bundled\tool floder? You can reinstall this extension if lsp_jsonrpc.py not exists.

The file lsp_jsonrpc.py does exist, and I have attempted to reinstall the extension, but the error still persists.

image

EeyoreLee commented 1 month ago

@xiaomoy - Could you run

import sys
print(sys.path)

in a .py file anywhere, like d:\Portables\python-3.13.0-embed-amd64\python.exe c:\Users\1\Desktop\python13_path.py, to check whether c:\Users\1\Desktop in the sys.path. I think this's the python interpreter issue, the embed suffix may not a suitable interpreter that automatic add the running directory to sys.path. Could u use another python interpreter or use the setting yapf.interpreter to choice another interpreter different from your current project needed.

xiaomoy commented 1 month ago

@xiaomoy - Could you run

import sys
print(sys.path)

in a .py file anywhere, like d:\Portables\python-3.13.0-embed-amd64\python.exe c:\Users\1\Desktop\python13_path.py, to check whether c:\Users\1\Desktop in the sys.path. I think this's the python interpreter issue, the embed suffix may not a suitable interpreter that automatic add the running directory to sys.path. Could u use another python interpreter or use the setting yapf.interpreter to choice another interpreter different from your current project needed.

I ran this code, and it produced the following output.

['D:\\Portables\\python-3.13.0-embed-amd64\\python313.zip', 'D:\\Portables\\python-3.13.0-embed-amd64', 'D:\\Portables\\python-3.13.0-embed-amd64\\Lib\\site-packages']

I will try the method you mentioned. So, does that mean the embedded cannot be used directly?

EeyoreLee commented 1 month ago

@xiaomoy - the directory of the python entrance will insert to the head of sys.path. It seems like the python-3.13.0-embed-amd64 will not complete this process automatically. You can add a code snipet in the lsp_server, like

import sys
import os
sys.path.insert(0, os.path.dirname(__file__))

Or could you tell me roughly what kind of scenario would require using that interpreter? So I can consider whether it's a general case and then add that code on the extension side.

xiaomoy commented 1 month ago

@xiaomoy - the directory of the python entrance will insert to the head of sys.path. It seems like the python-3.13.0-embed-amd64 will not complete this process automatically. You can add a code snipet in the lsp_server, like

import sys
import os
sys.path.insert(0, os.path.dirname(__file__))

Or could you tell me roughly what kind of scenario would require using that interpreter? So I can consider whether it's a general case and then add that code on the extension side.

Thanks for your help, I have resolved the issue. I ended up installing Python using the installer instead of using the embedded version.