VSCode Ruff doesn't work: Python interpreter missing:
SUPERustam opened this issue · 12 comments
Hi! ruff-lsp
requires Python to be installed on your system. You'll need to configure VSCode to use a Python interpreter as described in the error message.
I'm not sure why it's not finding the Python installation you have. Could you share more details about where your Python is installed? i.e. which python
? What happens if you configure it directly?
Alternatively, our new server does not require a Python interpreter. @charliermarsh has pointed out this isn't true until #479
I already have Python on my machine, these my python interpreters:
/usr/bin/python3 (3.9)
/opt/homebrew/bin/python3 (3.12.3)
I have ~/.vscode/extensions/ms-python.python-2024.8.0
, but it doesn't work and I don't know where to find the right ms-python.python
(it's weird because I am on Mac not on Windows)&
I don't change any settings of ruff
extenstion. This's my default package.json in ~/.vscode/extensions/charliermarsh.ruff-2024.26.0-darwin-arm64
package.json
Previously, before latests updates of extension (or vscode?
) all my ruff staff work fine on this machine. I don't even change settings of vscode-ruff, all work perfectly fine out of the box.
To clarify, I believe ms-python.python
is the VS Code Python extension, not Python itself. So it's required regardless of operating system.
I'm just looking through the history to see if we changed anything related to this and I'm not seeing anything relevant.
Thank you, @charliermarsh and @zanieb!!!
Yes, VS Code didn't recognize my interpreter, but after setting it, everything immediately started working fine.
I'm finding this doesn't work when I have many folders in the workspace each with a different Python interpreter path. I am using the python.defaultInterpreterPath
attribute to set it at the folder level within the workspace. It seems like it's picking the first one it finds.
It seems like it's picking the first one it finds.
Yes, that's the current behavior (it's mentioned in the docs: https://docs.astral.sh/ruff/editors/settings/#interpreter). What's your use-case for requiring different Python interpreter in a multi-root workspace w.r.t. Ruff?
Having many Python packages with different interpreters (i.e. using hatch
) should be a common use case. The hiccup with picking the first package in the workspace is that it doesn't work if that first package is not a Python package, and therefore has no Python interpreter associated with it. In my case, the first package in the workspace is a TS package.
@manmartgarc I don't think it has anything to do with a package. Can you what problem are you facing with the Ruff extension? Is it not showing any diagnostics? Is the extension not loading?
It's not finding the python interpreter unless I select a Python interpreter on the package-level .vscode
config file
@manmartgarc Maybe we should take this discussion in a new issue. Can you provide the project structure? And, how are you opening VS Code, like do you have a .code-workspace
file? I'm not sure if we can do anything here as we basically ask VS Code (via the API) to get the interpreter details. If VS Code can't detect it, Ruff won't work. You can also provide the interpreter in ruff.interpreter
setting.