Skip to content

VSCode Ruff doesn't work: Python interpreter missing: #493

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

Closed
SUPERustam opened this issue Jun 7, 2024 · 14 comments
Closed

VSCode Ruff doesn't work: Python interpreter missing: #493

SUPERustam opened this issue Jun 7, 2024 · 14 comments

Comments

@SUPERustam
Copy link

I installed latest version of python, vs code and ruff (also ruff-lsp in my .env), but get error and can't format code in jupyter files/python files.
image

My system:

  1. Apple Silicon chip
  2. MacOS Sonoma 14.5
  3. VSCode 1.90.0
  4. Python 3.12.3
  5. Extension: Realise 2024-06-05, 21:28:08
  6. Ruff 0.4.8, ruff-lsp 0.0.53
@zanieb
Copy link
Member

zanieb commented Jun 7, 2024

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

@SUPERustam
Copy link
Author

SUPERustam commented Jun 8, 2024

I already have Python on my machine, these my python interpreters:

  1. /usr/bin/python3 (3.9)
  2. /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.

@charliermarsh
Copy link
Member

To clarify, I believe ms-python.python is the VS Code Python extension, not Python itself. So it's required regardless of operating system.

@charliermarsh
Copy link
Member

I'm just looking through the history to see if we changed anything related to this and I'm not seeing anything relevant.

@charliermarsh
Copy link
Member

Do you have a Python interpreter configured in the VS Code window? E.g., in the bottom right here?

Screenshot 2024-06-08 at 4 35 08 PM

@SUPERustam
Copy link
Author

Thank you, @charliermarsh and @zanieb!!!
Yes, VS Code didn't recognize my interpreter, but after setting it, everything immediately started working fine.

@manmartgarc
Copy link

manmartgarc commented Aug 30, 2024

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.

@dhruvmanila
Copy link
Member

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?

@manmartgarc
Copy link

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.

@dhruvmanila
Copy link
Member

@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?

@manmartgarc
Copy link

It's not finding the python interpreter unless I select a Python interpreter on the package-level .vscode config file

@dhruvmanila
Copy link
Member

@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.

@b4stien
Copy link

b4stien commented Feb 26, 2025

There is something wrong with multi-root packages.

If I have the following structure :

- folder1
  -  .venv/
  - ...
  - pyproject.toml <- using ruff 0.8.x
- folder2
  -  .venv/
  - ...
  - pyproject.toml  <- using ruff 0.9.x

The extension will use folder1/.venv/bin/ruff to lint/format files in the folder2 directory, which is not want I want. Is there any way to tell it to use the ruff binary from the venv of the current folder?

FYI this is how black and mypy extensions correctly works with the fromEnvironment setting.

@dhruvmanila
Copy link
Member

@b4stien Let's take this discussion in a new issue #706

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

6 participants