微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何让黑色——python 格式化程序——在 vscode 开发容器上工作?

如何解决如何让黑色——python 格式化程序——在 vscode 开发容器上工作?

我目前是一个开发容器中的开发人员,我正在尝试使用 black 作为 python 的格式化程序。但是,我没能成功。这是我的.devcontainer.json

{
    "name": "api","dockerComposeFile": ["../docker-compose.yml","../docker-compose.devcontainer.yml"],"service": "api","workspaceFolder": "/workspace/api","settings": {
        "python.defaultInterpreterPath": "/usr/local/lib/python3.8","python.formatting.provider":"black","python.formatting.blackPath":"/usr/local/lib/python3.8/site-packages/black","python.linting.enabled": true,"python.linting.pylintEnabled": true,"python.linting.mypyEnabled":true,"editor.insertSpaces": true,"editor.tabSize": 4,"editor.detectIndentation":false,"editor.formatOnSave":true,},"shutdownAction": "none","extensions": ["ms-python.python","ms-python.vscode-pylance","ms-azuretools.vscode-docker"],//this is port forwarding for the debugger
    "forwardPorts": [8000]
}

解决方法

我更新了 python 和 black 的路径并重建了容器,然后在右下角的钟上有一个小点。我点击了它。我记不清这条消息了,但它要求我切换到 python 格式(类似的东西)我点击确定,它起作用了!

{
    "name": "api","dockerComposeFile": ["../docker-compose.yml","../docker-compose.devcontainer.yml"],"service": "api","workspaceFolder": "/workspace/api","settings": {
        "python.defaultInterpreterPath": "/usr/local/bin/python","python.formatting.provider":"black","python.formatting.blackPath":"/usr/local/bin/black","python.linting.enabled": true,"python.linting.pylintEnabled": true,"python.linting.mypyEnabled":true,"editor.insertSpaces": true,"editor.tabSize": 4,"editor.detectIndentation":false,"editor.formatOnSave":false,"[python]": {
            "editor.formatOnSave": true
        },"python.testing.pytestPath":"/usr/local/bin/pytest","python.testing.pytestEnabled":true
    },"shutdownAction": "none","extensions": ["ms-python.python","ms-python.vscode-pylance","ms-azuretools.vscode-docker"],//this is port forwarding for the debugger
    "forwardPorts": [8000]
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。