microsoft / vscode-pylint

Linting support for python using the pylint library.
https://marketplace.visualstudio.com/items?itemName=ms-python.pylint
MIT License
70 stars 34 forks source link

Pylint client: couldn't create connection to server. #532

Closed STPiv closed 6 months ago

STPiv commented 6 months ago

A couple of weeks ago Pylint stopped working for me in VSCode. I've searched the web and have not found a fix. I've seen posts about other issues that are close to but not the same as mine and tried what they've suggested:

I have other extensions (autoPep8, Pylance, iSort, Python Debugger) that are able to connect to the python server and work. Just pylint is messing with me.

I have much of my setup synchronized between work and home computers and the problem happens on both.

Here is the Pylint output log:

2024-03-15 12:22:20.747 [info] No interpreter found from setting pylint.interpreter
2024-03-15 12:22:20.747 [info] Getting interpreter from ms-python.python extension for workspace c:\Development\GitHub
2024-03-15 12:22:20.752 [info] Interpreter from ms-python.python extension for c:\Development\GitHub: c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe
2024-03-15 12:22:20.752 [info] Server: Stop requested
2024-03-15 12:22:20.753 [error] Server: Stop failed: Error: Client is not running and can't be stopped. It's current state is: startFailed
2024-03-15 12:22:20.753 [info] No interpreter found from setting pylint.interpreter
2024-03-15 12:22:20.753 [info] Getting interpreter from ms-python.python extension for workspace c:\Development\Workspaces
2024-03-15 12:22:20.754 [info] No interpreter found from setting pylint.interpreter
2024-03-15 12:22:20.754 [info] Getting interpreter from ms-python.python extension for workspace c:\Development\GitHub
2024-03-15 12:22:20.755 [info] No interpreter found from setting pylint.interpreter
2024-03-15 12:22:20.755 [info] Getting interpreter from ms-python.python extension for workspace c:\Development\GitLab
2024-03-15 12:22:20.756 [info] No interpreter found from setting pylint.interpreter
2024-03-15 12:22:20.756 [info] Getting interpreter from ms-python.python extension for workspace c:\Development\PROJECT\foundation
2024-03-15 12:22:20.757 [info] No interpreter found from setting pylint.interpreter
2024-03-15 12:22:20.757 [info] Getting interpreter from ms-python.python extension for workspace c:\Development\PROJECT\exosim
2024-03-15 12:22:20.758 [info] No interpreter found from setting pylint.interpreter
2024-03-15 12:22:20.758 [info] Getting interpreter from ms-python.python extension for workspace c:\Development\PROJECT
2024-03-15 12:22:20.781 [info] Interpreter from ms-python.python extension for c:\Development\Workspaces: c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe
2024-03-15 12:22:20.781 [info] Interpreter from ms-python.python extension for c:\Development\GitHub: c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe
2024-03-15 12:22:20.781 [info] Interpreter from ms-python.python extension for c:\Development\GitLab: c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe
2024-03-15 12:22:20.781 [info] Interpreter from ms-python.python extension for c:\Development\PROJECT\foundation: c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe
2024-03-15 12:22:20.781 [info] Interpreter from ms-python.python extension for c:\Development\PROJECT\exosim: c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe
2024-03-15 12:22:20.781 [info] Interpreter from ms-python.python extension for c:\Development\PROJECT: c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe
2024-03-15 12:22:20.789 [info] Server run command: c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe c:\MYUSER\.vscode\extensions\ms-python.pylint-2023.10.1\bundled\tool\lsp_server.py
2024-03-15 12:22:20.790 [info] Server: Start requested.
2024-03-15 12:22:20.790 [debug] Server State: Starting
2024-03-15 12:22:20.794 [debug] Server State: Stopped
2024-03-15 12:22:20.794 [info] [Error - 12:22:20 PM] Pylint client: couldn't create connection to server.
2024-03-15 12:22:20.794 [info] Launching server using command c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe failed. Error: spawn c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe ENOENT
2024-03-15 12:22:20.794 [error] Server: Start failed: Launching server using command c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe failed. Error: spawn c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe ENOENT
karthiknadig commented 6 months ago

Can you verify few things?

See if this python exists and you are able to run it from the terminal: c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe

Make sure this location has the following files: c:\MYUSER\.vscode\extensions\ms-python.pylint-2023.10.1\bundled\tool image

try running this manually from a terminal, it should not fail. If it ran successfully it will have a blank output waiting for you to terminate it.

c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe c:\MYUSER\.vscode\extensions\ms-python.pylint-2023.10.1\bundled\tool\lsp_server.py
STPiv commented 6 months ago

It works both from a regular command line and from the terminal window within VSCode. Here is the output from within the VSCODE terminal:

PS C:\Development> python
Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit(0)
PS C:\Development> C:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe
Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit(0)
PS C:\Development> C:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe C:\MYUSER\.vscode\extensions\ms-python.pylint-2023.10.1\bundled\tool\lsp_server.py 

^Z
PS C:\Development> 

I can even run Pylint in the terminal within VSCode:

PS C:\Development> pylint .\PROJECT\scripts\utilInterpretVerifyReportResults.py --max-line-length=120 --module-naming-style=camelCase --function-naming-style=camelCase
************* Module utilInterpretVerifyReportResults
PROJECT\scripts\utilInterpretVerifyReportResults.py:44:4: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
PROJECT\scripts\utilInterpretVerifyReportResults.py:78:4: C0103: Constant name "rc" doesn't conform to UPPER_CASE naming style (invalid-name)

------------------------------------------------------------------
Your code has been rated at 9.05/10 (previous run: 8.57/10, +0.48)
STPiv commented 6 months ago

All of those files are in the directory.

image

karthiknadig commented 6 months ago

@STPiv This is really strange. I don't see why it is failing to run. Can you try setting pylint.interpreter to explicitly point to the interpreter ? C:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe.

Do you happen to have case sensitivity on for any folders? like using fsutil.exe file setCaseSensitiveInfo C:\folder enable Do you have space or any non ascii characters in your user name?

STPiv commented 6 months ago

I set the interpreter directly. No change I do not think I have any case sensitivity set. Never typed that command you list. My username does not have special characters, other than "." between my user and the domain name. It looks like "STPiv.COMPANY".

The fact that this happens at home as well, where my user name is different and there is no domain, makes me think that it has to do with some setting that is synchronized. I can't remember if I have updated the computer at home to Python 3.12. It might be at 3.10 still.

I have wracked my brain to try to remember if I changed anything around when this started being a problem. The only thing I can think of is that I changed the value of the "type" key inside my IntelliSense "configurations" list in my Python debug config to "debugpy". I did that because I got a message that the value I had there before (which I can't recall for the life of me) was going to be deprecated soon.

EDIT: That is in the .VSCode/launch.json file for the workspace.

karthiknadig commented 6 months ago

Does this happen with a particular workspace or any workspace? Would it be possible to share the list of installed extensions? Also can you share similar part of the logs from autopep8 extension? basically part of the log that shows the command being used to launch the server.

The only thing I can think of is that I changed the value of the "type" key inside my IntelliSense "configurations" list in my Python debug config to "debugpy". I did that because I got a message that the value I had there before (which I can't recall for the life of me) was going to be deprecated soon.

That does not affect pylint extension.

STPiv commented 6 months ago

Trying another workspace was an interesting test. I opened another window of VSCode, picked a different workspace, and opened a python script. Pylint worked.

So, what does that mean?

STPiv commented 6 months ago

Here is a portion of the autopep8 log

2024-03-15 12:18:29.964 [info] c:\MYUSER\AppData\Local\Programs\Python\Python312\python.exe -m autopep8 --version
2024-03-15 12:18:29.964 [info] CWD Server: c:\Development\PROJECT
2024-03-15 12:18:30.600 [info] Version info for formatter running for C:\Development\PROJECT
autopep8 2.0.4 (pycodestyle: 2.11.1)

2024-03-15 12:18:30.601 [info] SUPPORTED autopep8>=1.7.0
karthiknadig commented 6 months ago

Trying another workspace was an interesting test. I opened another window of VSCode, picked a different workspace, and opened a python script. Pylint worked. So, what does that mean?

It looks like where pylint fails is a multi-root workspace. We need to investigate what in particular there is causing this. My current suspicion is that the current working directory is somehow incorrect and causing the server to fail to start with ENOENT.

STPiv commented 6 months ago

That was the hint!

Pylint: Cwd setting for the workspace that didn't work was ${filedirname} instead of ${fileDirname}.

I changed that setting and restarted VSCode and now Pylint is back to working.

STPiv commented 6 months ago

I thought I changed the Pyling: Cwd setting at the workspace, but I changed it for the user. Not sure why that caused trouble in one workspace and not another. Thing is, make a reference to the correct variable in the settings seems to have resolved my issue.

karthiknadig commented 6 months ago

I am glad we could figure this out. Happy Coding!

STPiv commented 6 months ago

Thanks for the help. I've been beating my head against it off and on for weeks. It helped to have another set of eyes.