简体   繁体   English

Formatter Black 不适用于我的 VScode Jupyter Notebooks?

[英]Formatter Black not working for my VScode Jupyter Notebooks?

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.尽管 autopep8 正在工作,但我的黑色格式化程序从几个月前开始在自动保存(延迟后)上格式化我的笔记本单元格时不再工作。 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:当我尝试格式化单元格时,output 如下所示:

> "~/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.如果 Black 已正确安装到您的虚拟环境中,并且您的 VSCode 项目指向正确的环境,则您不必首先提供black.exe的路径。 The package provides an entrypoint and should "just work" with the virtual environment activated. package 提供了一个入口点,并且应该在激活虚拟环境的情况下“正常工作”。

I suggest you remove the "python.formatting.blackPath" setting entirely.我建议您完全删除"python.formatting.blackPath"设置。

If for some reason you want to provide an explicit path to Black, you'll need to change that setting.如果出于某种原因您想提供一个显式的 Black 路径,您需要更改该设置。 Don't point to the directory in Lib/site-packages/ ;不要指向Lib/site-packages/中的目录; point to the binary in Scripts/ , which should be something like指向Scripts/中的二进制文件,应该类似于

~/Documents/GitHub/DataScience/pyenv/Scripts/black.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM