microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.72k stars 765 forks source link

PyLance seems to be looking in the wrong directory for Python.exe #5337

Closed connorferster closed 10 months ago

connorferster commented 10 months ago

Environment data

Repro Steps

Can't really say. PyLance normally works for me. I noticed this morning that when I launched VS Code it was not working. I found the Python Language Server output log and saw that it should be looking in the directory:

C:\Users\username\miniconda3\envs\environment_name\python.exe

Instead it is looking here:

C:\Users\username\miniconda3\envs\environment_name\Scripts\python.exe

Last I remember there is never a python.exe in "Scripts". Seems to be a mistake in the PyLance code.

Expected behavior

PyLance does its magic!

Actual behavior

No magic :(

Logs

I did not set the python.analysis.logLevel to "Trace". I think the problem is apparent from the existing output but let me know if needed.

Logs have been anonymized to remove internal project identifiers and usernames.

2024-01-09 09:53:03.385 [info] ERROR:pygls.protocol:Failed to handle request 1 textDocument/documentSymbol DocumentSymbolParams(text_document=TextDocumentIdentifier(uri='file:///c%3A/Users/MyUserName/pycode/my_project/src/my_project_package/dash_app/callbacks/my_app_callbacks.py'), work_done_token=None, partial_result_token=None)
Traceback (most recent call last):
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\pygls\protocol.py", line 340, in _handle_request
    self._execute_request(msg_id, handler, params)
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\pygls\protocol.py", line 264, in _execute_request
    self._send_response(msg_id, handler(params))
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi_language_server\server.py", line 435, in document_symbol
    jedi_script = jedi_utils.script(server.project, document)
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi_language_server\jedi_utils.py", line 118, in script
    return Script(code=document.source, path=document.path, project=project)
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi\api\__init__.py", line 119, in __init__
    self._inference_state = InferenceState(
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi\inference\__init__.py", line 87, in __init__
    environment = project.get_environment()
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi\api\project.py", line 245, in get_environment
    self._environment = create_environment(self._environment_path, safe=False)
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi\api\environment.py", line 367, in create_environment
    return Environment(_get_executable_path(path, safe=safe), env_vars=env_vars)
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi\api\environment.py", line 380, in _get_executable_path
    raise InvalidPythonEnvironment("%s seems to be missing." % python)
jedi.api.environment.InvalidPythonEnvironment: C:\Users\MyUserName\miniconda3\envs\my_env_name\Scripts\python.exe seems to be missing.

2024-01-09 09:53:03.385 [info] [Error - 9:53:03 AM] Request textDocument/documentSymbol failed.
2024-01-09 09:53:03.385 [info]   Message: jedi.api.environment.InvalidPythonEnvironment: C:\Users\MyUserName\miniconda3\envs\my_env_name\Scripts\python.exe seems to be missing.
  Code: -32602 
{'traceback': ['  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\pygls\\protocol.py", line 340, in _handle_request\n    self._execute_request(msg_id, handler, params)\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\pygls\\protocol.py", line 264, in _execute_request\n    self._send_response(msg_id, handler(params))\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi_language_server\\server.py", line 435, in document_symbol\n    jedi_script = jedi_utils.script(server.project, document)\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi_language_server\\jedi_utils.py", line 118, in script\n    return Script(code=document.source, path=document.path, project=project)\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi\\api\\__init__.py", line 119, in __init__\n    self._inference_state = InferenceState(\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi\\inference\\__init__.py", line 87, in __init__\n    environment = project.get_environment()\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi\\api\\project.py", line 245, in get_environment\n    self._environment = create_environment(self._environment_path, safe=False)\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi\\api\\environment.py", line 367, in create_environment\n    return Environment(_get_executable_path(path, safe=safe), env_vars=env_vars)\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi\\api\\environment.py", line 380, in _get_executable_path\n    raise InvalidPythonEnvironment("%s seems to be missing." % python)\n']}
2024-01-09 09:53:03.388 [info] ERROR:pygls.protocol:Failed to handle request 2 textDocument/codeAction CodeActionParams(text_document=TextDocumentIdentifier(uri='file:///c%3A/Users/MyUserName/pycode/my_env_name/src/my_project_package/dash_app/callbacks/my_app_callbacks.py'), range=485:56-485:56, context=CodeActionContext(diagnostics=[], only=None, trigger_kind=<CodeActionTriggerKind.Automatic: 2>), work_done_token=None, partial_result_token=None)
Traceback (most recent call last):
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\pygls\protocol.py", line 340, in _handle_request
    self._execute_request(msg_id, handler, params)
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\pygls\protocol.py", line 264, in _execute_request
    self._send_response(msg_id, handler(params))
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi_language_server\server.py", line 549, in code_action
    jedi_script = jedi_utils.script(server.project, document)
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi_language_server\jedi_utils.py", line 118, in script
    return Script(code=document.source, path=document.path, project=project)
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi\api\__init__.py", line 119, in __init__
    self._inference_state = InferenceState(
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi\inference\__init__.py", line 87, in __init__
    environment = project.get_environment()
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi\api\project.py", line 245, in get_environment
    self._environment = create_environment(self._environment_path, safe=False)
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi\api\environment.py", line 367, in create_environment
    return Environment(_get_executable_path(path, safe=safe), env_vars=env_vars)
  File "c:\Users\MyUserName\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\jedilsp\jedi\api\environment.py", line 380, in _get_executable_path
    raise InvalidPythonEnvironment("%s seems to be missing." % python)
jedi.api.environment.InvalidPythonEnvironment: C:\Users\MyUserName\miniconda3\envs\my_env_name\Scripts\python.exe seems to be missing.

2024-01-09 09:53:03.389 [info] [Error - 9:53:03 AM] Request textDocument/codeAction failed.
2024-01-09 09:53:03.389 [info]   Message: jedi.api.environment.InvalidPythonEnvironment: C:\Users\MyUserName\miniconda3\envs\my_env_name\Scripts\python.exe seems to be missing.
  Code: -32602 
{'traceback': ['  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\pygls\\protocol.py", line 340, in _handle_request\n    self._execute_request(msg_id, handler, params)\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\pygls\\protocol.py", line 264, in _execute_request\n    self._send_response(msg_id, handler(params))\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi_language_server\\server.py", line 549, in code_action\n    jedi_script = jedi_utils.script(server.project, document)\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi_language_server\\jedi_utils.py", line 118, in script\n    return Script(code=document.source, path=document.path, project=project)\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi\\api\\__init__.py", line 119, in __init__\n    self._inference_state = InferenceState(\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi\\inference\\__init__.py", line 87, in __init__\n    environment = project.get_environment()\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi\\api\\project.py", line 245, in get_environment\n    self._environment = create_environment(self._environment_path, safe=False)\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi\\api\\environment.py", line 367, in create_environment\n    return Environment(_get_executable_path(path, safe=safe), env_vars=env_vars)\n', '  File "c:\\Users\\MyUserName\\.vscode\\extensions\\ms-python.python-2023.22.1\\pythonFiles\\lib\\jedilsp\\jedi\\api\\environment.py", line 380, in _get_executable_path\n    raise InvalidPythonEnvironment("%s seems to be missing." % python)\n']}
rchiodo commented 10 months ago

Thanks for the issue but it looks to me like you're using Jedi, not Pylance. Those logs are from the Python extension (not the Pylance extension) and it looks like it's running Jedi.

You might log an error on the jedi language server, or switch your language server to Pylance.

That setting is here: image