microsoft / vscode-flake8

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

Flake8 extension can't find interpreter in multi-root workspace #238

Closed KoBOLL closed 1 year ago

KoBOLL commented 1 year ago

I have a directory structure:

├── .vscode
|   └── my_workspace.code-workspace
├── A
|   ├── .venv_3_5
|   ├── .vscode
|   |   └── settings.json
|   └── src
|       └── ...
└── B
    ├── .venv_3_9
    ├── .vscode
    |   └── settings.json
    └── src
        └── ...

In file /path/to/B/.vscode/settings.json I have:

  "flake8.interpreter": [
    "/path/to/B/.venv_3_9/bin/python"
  ],

But Flake8 extension gives an error:

[error] Python version 3.5 is not supported.
[error] Selected python path: /path/to/A/.venv_3_5/bin/python
[error] Supported versions are 3.8 and above.
[error] Python interpreter missing:
[Option 1] Select python interpreter using the ms-python.python.
[Option 2] Set an interpreter using "flake8.interpreter" setting.
Please use Python 3.8 or greater.

Or maybe I'm doing something wrong?

KoBOLL commented 1 year ago

Oh, I'm sorry, extension version is v2023.8.0 and VSCode version is 1.83.1

karthiknadig commented 1 year ago

@KoBOLL If it is a multi root workspace then we use the interpreter from the first workspace to start the server. The issue is that even if you put B in the first place, we need to verify support for each of the roots.

You will need to do two things here:

  1. Make sure both A and B use a supported python version.
  2. Point the flake8 in A to use the one from its environment, since it is using 3.5.

Lets try this: Settings for A: (${workspaceFolder:B} is a way to point to the workspace B from A)

    "flake8.interpreter": ["${workspaceFolder:B}/.venv_3_9/bin/python"],
    "flake8.path": ["${workspaceFolder}/.venv_3_5/bin/flake8"]

Settings for B:

    "flake8.interpreter": ["${workspaceFolder}/.venv_3_9/bin/python"]
KoBOLL commented 1 year ago

It wasn't obvious, but it definitely worked. Thank you!