配置Visual Studio代码以在Windows上以bash运行Python

Pio*_*rek 7 python visual-studio-code windows-subsystem-for-linux

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

我试图做的:

更改默认shell settings.json:

{
    "terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe"
}
Run Code Online (Sandbox Code Playgroud)

将任务添加tasks.jsonpython以文件名作为参数的run 命令:

{
    // 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}"]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

这里有一些问题需要解决:

  1. 任务没有像我想的那样在bash中运行
  2. 要访问C驱动器,我需要替换 C:\/mnt/c文件路径

您可以与我的解决方案分享这些问题吗?

Stu*_*ock 0

我没有 Windows 10 bash,但我想问题是你实际上并没有尝试运行 Python。您正在尝试运行bash(然后运行python)。尝试将命令设置为bashwith params ["python", "$file"]