安装 anaconda3 后,黑色格式化程序在 VSCode 中不起作用 [英] Black formatter does not work in VSCode after installing anaconda3
问题描述
settings.json
settings.json
"python.pythonPath": "/Users/brandonwie/opt/anaconda3/bin/python",
"[python]": {
"editor.tabSize": 4
},
"python.languageServer": "Pylance",
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.formatting.blackPath": "/Users/brandonwie/opt/anaconda3/bin/black",
"python.showStartPage": false,
"python.formatting.provider": "black",
"python.analysis.typeCheckingMode": "basic",
我正在使用 VSCode
,我已经安装了 anaconda3
来尝试 conda
环境,然后 black
在我开始使用 conda Python 后,格式化程序立即停止工作(我不知道这是因为 conda Python).所以我用 (conda) pip 安装了 black,但没有任何效果..
I'm using VSCode
, I've installed anaconda3
to try conda
environment, but then black
formatter stopped working right after I start using conda Python(I don't know it's because of conda Python). So I installed black with (conda) pip, but nothing is working..
最初,setting.json
中的 blackPath
设置为 /usr/local/bin/black
.在我使用 conda 安装和设置 VSCode 之前,黑色格式化程序一直正常工作,当我保存文件找不到黑色"时,右下角会弹出一个窗口.类似的东西.(因为保存格式")我尝试将路径更改为 /usr/...
和 /Users/
来回,但是效果不佳.
Initially, the blackPath
in setting.json
was set to /usr/local/bin/black
. The black formatter was working flawlessly until I install and set up VSCode with conda, there was a pop up at the right bottom when I saved a file "cannot find black" something like that.(because of 'format on save') I've tried changing the path to /usr/...
and /Users/
back and forth, but doesn't work as well.
我该如何解决这个问题?
How can I solve this issue?
推荐答案
您无需在 Settings.json 中指定 blackpath.
You don't need to specify the blackpath in Settings.json.
运行
pip uninstall black
删除当前激活的conda环境中的黑色;
Run
pip uninstall black
to delete black in current activated conda environment;
在 Settings.json 中,设置 "python.formatting.provider":"black",
In Settings.json, set "python.formatting.provider": "black",
转到 .py 文件,然后按 Ctrl+S 保存它.同时会弹出一个通知:
Turn to .py file then press Ctrl+S to save it. At the same time, there will be an notification popping up:
点击是和使用 Pip 安装:
安装后,您可以使用黑色成功格式化您的文件.
After its installation, you can use black to format your file successfully.
这篇关于安装 anaconda3 后,黑色格式化程序在 VSCode 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!