Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jedi searches the python interpreter in the wrong path. #1975

Open
Sniper10754 opened this issue Dec 8, 2023 · 8 comments
Open

Jedi searches the python interpreter in the wrong path. #1975

Sniper10754 opened this issue Dec 8, 2023 · 8 comments

Comments

@Sniper10754
Copy link

Im a linux user which is using jedi in the python vscodium extension, after editing with jedi for a bit it started searching for the python interpreter in bin/python making it relative instead of searching it from the root, like it should be (/bin/python), heres the stack trace which jedi outputs

Traceback (most recent call last):
  File "/home/sniper/.vscode-oss/extensions/ms-python.python-2023.22.0/pythonFiles/lib/jedilsp/pygls/protocol.py", line 340, in _handle_request
    self._execute_request(msg_id, handler, params)
  File "/home/sniper/.vscode-oss/extensions/ms-python.python-2023.22.0/pythonFiles/lib/jedilsp/pygls/protocol.py", line 264, in _execute_request
    self._send_response(msg_id, handler(params))
                                ^^^^^^^^^^^^^^^
  File "/home/sniper/.vscode-oss/extensions/ms-python.python-2023.22.0/pythonFiles/lib/jedilsp/jedi_language_server/server.py", line 549, in code_action
    jedi_script = jedi_utils.script(server.project, document)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sniper/.vscode-oss/extensions/ms-python.python-2023.22.0/pythonFiles/lib/jedilsp/jedi_language_server/jedi_utils.py", line 118, in script
    return Script(code=document.source, path=document.path, project=project)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sniper/.vscode-oss/extensions/ms-python.python-2023.22.0/pythonFiles/lib/jedilsp/jedi/api/__init__.py", line 119, in __init__
    self._inference_state = InferenceState(
                            ^^^^^^^^^^^^^^^
  File "/home/sniper/.vscode-oss/extensions/ms-python.python-2023.22.0/pythonFiles/lib/jedilsp/jedi/inference/__init__.py", line 87, in __init__
    environment = project.get_environment()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sniper/.vscode-oss/extensions/ms-python.python-2023.22.0/pythonFiles/lib/jedilsp/jedi/api/project.py", line 245, in get_environment
    self._environment = create_environment(self._environment_path, safe=False)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sniper/.vscode-oss/extensions/ms-python.python-2023.22.0/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 "/home/sniper/.vscode-oss/extensions/ms-python.python-2023.22.0/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: bin/python seems to be missing.
@davidhalter
Copy link
Owner

This is searching bin/python in the virtual environment that was probably specified here. I'm pretty sure there is some misconfiguration here where a project exists that points towards a now defunct venv.

@Sniper10754
Copy link
Author

i never created a venv, neither i have a defunct one in the directory im modifying things in

@davidhalter
Copy link
Owner

The problem is that I have no way to debug this. This is not a pure Jedi call. I don't know what project is at this point. I have no idea about your system about installed Python version. So unless you start trying to debug this yourself (the environment.py code is extremely simple), I'm afraid I cannot help you.

I would be surprised if this was a fundamental issue. Jedi has been downloaded about 800 million times and it's used widely. This code hasn't changed a lot in a few years. So either it's a really strange edge case or something in your system is just broken.

@lcruz99
Copy link

lcruz99 commented Dec 11, 2023

same issue happening since 3 days ago

@Sniper10754
Copy link
Author

I found a simple fix: nuke $HOME/.cache/jedi, so i assume the problem is somehow related to cache

@wsldankers
Copy link

In jedilsp/jedi/api/project.py line 244 where it says:

if self._environment_path is not None:

it should instead read:

if self._environment_path:

…because this setting can also be the empty string when left unconfigured.

@davidhalter
Copy link
Owner

@wsldankers No. An empty path should behave like an empty path. I'm not sure what exactly happens in that case. If an empty string never provides any useful result we should let the user know that and raise an exception instead of just swallowing a very and invalid value. If it implies the "current working directory"? that might be a fine behavior.

@wsldankers
Copy link

wsldankers commented Jan 22, 2024

Well if that's the case, how do I change it from an empty string to None? I have no idea.
Edit: that's probably IDE dependent. I'll need to look into that first.
Edit 2: this MAY be fixed in microsoft/vscode-python#22713 but that fix is not in a release yet.

In my case it's the vscode plugin that is sending an empty string as environmentPath over jsonrpc. If that is incorrect behavior it's not a bug in jedi. If this is the same issue that @Sniper10754 is experiencing, then this bug can probably be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants