将 Windows Linux 子系统 bash 与 VS Code 结合使用时出现“没有此类文件或目录”

red*_*tel 5 python windows visual-studio-code windows-subsystem-for-linux

我在带有 Windows Linux 子系统和 Ubuntu 18.04 的 Windows 10 上使用 VS Code。

我试图做的是使用 VS Code 作为 python 开发环境,以 bash 作为终端,并在 Ubuntu 系统上安装 python3 解释器作为默认的 python 可执行文件。

在我的用户配置中,我有:

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

设置,并且在 Ubuntu 下安装了 python3 并且python是它的别名。

当我尝试执行 python 文件时,出现以下错误:

/usr/bin/python3: can't open file 'c:/Users/R ... /test.py': [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)

我的感觉是我需要让 VS Code 将相对于 Linux 子系统而不是 Windows C:\ 的路径传递给解释器。我怎样才能做到这一点?

red*_*tel 3

虽然 Visual Studio Code for Windows 似乎没有官方支持,但具有 runInTerminal 设置的插件“Code Runner”修复了此问题。

它将“运行代码”(Alt-Ctrl-N) 添加到打开的编辑器的右键单击窗口。

如果您设置了用户设置:

“code-runner.runInTerminal”:true

然后运行代码,它将正确的文件名传递给终端环境的默认可执行文件。