简体   繁体   English

安装 anaconda3 后,黑色格式化程序在 VSCode 中不起作用

[英]Black formatter does not work in VSCode after installing anaconda3

settings.json设置.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",

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).我正在使用VSCode ,我已经安装了anaconda3来尝试conda环境,但是在我开始使用 conda Python 后black格式化程序立即停止工作(我不知道这是因为 conda Python)。 So I installed black with (conda) pip, but nothing is working..所以我用(conda)pip 安装了黑色,但没有任何效果..

Initially, the blackPath in setting.json was set to /usr/local/bin/black .最初, setting.json中的blackPath设置为/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.在我使用 conda 安装和设置 VSCode 之前,黑色格式化程序工作完美,当我保存类似“找不到黑色”的文件时,右下角会弹出一个窗口。(因为“保存时格式化”)我我尝试来回更改/usr/.../Users/的路径,但效果不佳。

How can I solve this issue?我该如何解决这个问题?

You don't need to specify the blackpath in Settings.json.您无需在 Settings.json 中指定黑色路径。

  1. Run pip uninstall black to delete black in current activated conda environment;运行pip uninstall black删除当前激活的 conda 环境中的黑色;

  2. In Settings.json, set "python.formatting.provider": "black",在 Settings.json 中,设置"python.formatting.provider": "black",

  3. Turn to.py file then press Ctrl+S to save it.转到 .py 文件,然后按Ctrl+S保存。 At the same time, there will be an notification popping up:同时会弹出一个通知:

    在此处输入图像描述

    Click Yes and Install using Pip :单击使用 Pip 安装 在此处输入图像描述

After its installation, you can use black to format your file successfully.安装后,您可以使用黑色成功格式化文件。 在此处输入图像描述

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

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