How do you tell the version of the Python formatter being used by VS Code?

Viewed 2915

As stated on this answer, one can check (and set) on settings.json the formatters used by VS Code.

For Python, I use black:

settings.json

...
"python.formatting.provider": "black"
...

I think I found an issue involving black, but I'm only able to reproduce it in VS Code, not when running it from the terminal.

I'd like to know which version (or even better, the location) of the black binary is being used by VS Code. Ideally, I would also like to change it, in order to check on which versions I can (or cannot) reproduce the issue.

What I know for sure is that VS Code is not using the black binary on my path; autoformatting keeps working even if I remove it from the path. ( e.g.: mv /home/sam/.local/bin/black /home/sam/.local/bin/black.bak)

2 Answers

Open OUTPUT panel, choose Python channel in the drop-down list, then format the document, you will get it.

If you want to use a custom version of black, you can specify the Black Path: Specified

After you select the right environment, take the command 'pip show black'. It will tell you the location of black which you are using. Or you can just take the command 'pip install black', if the black has been installed, it will show you: "Requirement already satisfied: black in {the location of black} {version}". In fact, if you are using the virtual environment, it just locates in the xxx.venv\lib\site-packages.

In a python environment, you can only have one version of one package at one time. You can take these commands: 1. 'pip show black' to get the specific information of the black package. 2. "pip install 'black=={version}'" to install the specific version of black. 3. 'pip install --upgrade black' to install the last version of black.

Related