为什么 Visual Studio Code 不能识别我的 WSL bash python?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48524846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:47:57  来源:igfitidea点击:

Why doesn't Visual Studio Code recognize my WSL bash python?

pythonbashvisual-studio-codewindows-subsystem-for-linux

提问by urig

I am running Visual Studio Code on Windows 10 with WSL bash as its terminal:

我在 Windows 10 上运行 Visual Studio Code,使用 WSL bash 作为终端:

"terminal.integrated.shell.windows": "C:/Windows/sysnative/bash.exe"

In WSL bash I have both python(v2.7) and python3(v3.6) installed.

在 WSL bash 中,我同时安装了python(v2.7) 和python3(v3.6)。

I have installed the Python extension for VS Code. Unfortunately VS Code fails to recognize either version of Python in WSL bash.

我已经为 VS Code 安装了 Python 扩展。不幸的是,VS Code 无法在 WSL bash 中识别任一版本的 Python。

For example when I try to discover tests, I get the following error in the Python Test Log output window:

例如,当我尝试发现测试时,我在 Python 测试日志输出窗口中收到以下错误:

Test Discovery failed:

Error: spawn python ENOENT

测试发现失败:

错误:生成 python ENOENT

How can I configure VS Code to work with Python form WSL bash?

如何配置 VS Code 以使用 Python 表单 WSL bash?

Note: I'm pretty sure I need to configure a path to Python in the "python.pythonPath"key in VS Code's user settings file. I am unsure of which path to put as the value though.

注意:我很确定我需要"python.pythonPath"在 VS Code 的用户设置文件中的键中配置 Python 的路径。我不确定将哪个路径作为值。

回答by Brett Cannon

Support for WSL is done through the "WSL - Remote" extension. There is a WSL blog postwhich covers how to get started.

对 WSL 的支持是通过“WSL - Remote”扩展完成的。有一篇WSL 博客文章介绍了如何开始。