My black formatter that used to work to format my notebook cells on autosave (after delay) is no longer working since months ago even though autopep8 is working. I use a virtual environment to work with my notebooks. I also installed black there. So here is my user settings:
"[python]": {
"editor.defaultFormatter": null,
"editor.insertSpaces": true,
"editor.tabSize": 4,
"editor.formatOnSave": true
},
"python.formatting.blackPath": "C:/Users/core i5/Documents/GitHub/DataScience/pyenv/Lib/site-packages/black",
The output when I try to format my cells look like this:
> "~/Documents/GitHub/DataScience/pyenv/Lib/site-packages/black" --diff --quiet ".\CPE 312\KNN-SVM-NaiveBayes\Hands-on Activity 4.1 K Nearest Neighbors.ipynb.e65891a52a42197e13c75efc5b59ebe7.tmp"
cwd: .
> "~/Documents/GitHub/DataScience/pyenv/Lib/site-packages/black" --version
Formatting with black failed.
You could either install the 'black' formatter, turn it off or use another formatter.
Error: spawn C:/Users/core i5/Documents/GitHub/DataScience/pyenv/Lib/site-packages/black ENOENT
Anyone know what to do? Thanks in advance!
If Black is correctly installed into your virtual environment, and if your VSCode project is pointing to the correct environment, you shouldn't have to provide a path to black.exe
in the first place. The package provides an entrypoint and should "just work" with the virtual environment activated.
I suggest you remove the "python.formatting.blackPath"
setting entirely.
If for some reason you want to provide an explicit path to Black, you'll need to change that setting. Don't point to the directory in Lib/site-packages/
; point to the binary in Scripts/
, which should be something like
~/Documents/GitHub/DataScience/pyenv/Scripts/black.exe
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.