安装 anaconda3 后,黑色格式化程序在 VSCode 中不起作用 [英] Black formatter does not work in VSCode after installing anaconda3

查看:37
本文介绍了安装 anaconda3 后,黑色格式化程序在 VSCode 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

  1. 运行pip uninstall black删除当前激活的conda环境中的黑色;

  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆