microsoft / vscode-black-formatter

Formatting support for Python using the Black formatter
https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter
MIT License
146 stars 35 forks source link

No interpreter found error #377

Closed AbdealiLoKo closed 8 months ago

AbdealiLoKo commented 8 months ago

The black vscode extension used to work for me fine earlier. Since a few days now - black formatting has not been working on vscode.

I checked the output, and I see the messages:

2023-11-09 14:40:30.362 [info] No interpreter found from setting black-formatter.interpreter
2023-11-09 14:40:30.362 [info] Getting interpreter from ms-python.python extension for workspace /home/abdealiloko/myapp
2023-11-09 14:40:30.363 [error] Python version 3.7 is not supported.
2023-11-09 14:40:30.364 [error] Selected python path: /home/abdealiloko/myapp/venv37/bin/python
2023-11-09 14:40:30.364 [error] Supported versions are 3.8 and above.
2023-11-09 14:40:30.364 [info] No interpreter found for /home/abdealiloko/myapp in settings or from ms-python.python extension
2023-11-09 14:40:30.364 [error] Python interpreter missing:
[Option 1] Select python interpreter using the ms-python.python.
[Option 2] Set an interpreter using "black-formatter.interpreter" setting.
 Please use Python 3.8 or greater.

Now, black is installed into my virtualenv already:

$ /home/abdealiloko/myapp/venv37/bin/black --version
black, 23.3.0 (compiled: yes)
Python (CPython) 3.7.16

And I am using vscode Black Formatter v2023.6.0

I guess earlier the black extension was using this black in my venv. Now, it is not ... And I am using py3.7 because I still need to support it for my project.

I guess what I can't understand is why the black in my venv37 is not being used by the extension anymore.

AbdealiLoKo commented 8 months ago

I always assumed that 2023.6.0 - implied that this was released in June 2023 ... But I just realized that 2023.6.0 was actually released 2 days ago.

On checking the issue tracker more - I see that this may be similar to https://github.com/microsoft/vscode-black-formatter/issues/372

Is the expected behavior that vscode-black will not support black installed in python 3.7 environments anymore ? Seems a bit inconvenient... but looks like that is expected behavior but not documented in the release notes ?

karthiknadig commented 8 months ago

@AbdealiLoKo The server that we use needs 3.8 or greater, but it can run black from 3.7 environment. You can set black-formatter.interpreter to a newer interpreter and then set the black-formatter.path to the path of black from your environment.

Another option is to pin the black-formatter extension to version 2023.4.* using "Install Another Version"

GF-Huang commented 4 months ago

Same issue, how to work with local conda env? It works well a few days ago.

image

karthiknadig commented 4 months ago

@GF-Huang Use Python: Select Interpreter to select an interpreter for your workspace.