python - 配置 Visual Studio Code 以在 Windows 上的 bash 中运行 Python

标签 python visual-studio-code windows-subsystem-for-linux

我想使用 Windows bash 控制台在 Visual Studio Code 中运行 python .py 文件。

我尝试做的事情:

settings.json 中更改默认 shell:

{
    "terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe"
}

tasks.json 中添加任务,以文件名作为参数运行 python 命令:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "python",
    "isShellCommand": true,
    "showOutput": "always",
    "tasks": [
        {
            "taskName": "Run python in bash",
            "suppressTaskName": true,
            "args": ["${file}"]
        }
    ]
}

这里有几个问题需要解决:

  1. 任务没有按照我的意愿在 bash 中运行
  2. 访问 C 驱动器 I need to replace C:\ 文件路径为 /mnt/c

你能分享我解决这些问题的方法吗?

最佳答案

我没有带 bash 的 Windows 10,但我想问题在于您实际上并没有尝试运行 Python。您正在尝试运行 bash(然后运行 ​​python)。尝试使用参数 ["py​​thon", "$file"] 将命令设置为 bash

关于python - 配置 Visual Studio Code 以在 Windows 上的 bash 中运行 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39751858/

相关文章:

python - 为什么 response.xpath ('//html' ) 的结果与 response.body 不同?

python - 属性错误 : 'bool' object has no attribute

python - 自动检测文件夹中的文件

visual-studio-code - 如何更改 vscode-server 目录

azure - WSL - 无法登录或从 azure 容器注册表提取镜像

python - WSL 上没有名为tensorflow.python.platform 的模块

python - InstaPy: "Error, unable to determine correct filename for 64bit linux"

html - VScode - 用值替换捕获的组

visual-studio-code - 查看 vscode 中未保存的更改

docker - WSL : Can't install docker on WSL 2, Ubuntu 18.04