VSCode for WSL:解释器的 python 版本错误

VSCode for WSL: wrong python version of the interpreter

我正在尝试将 VScode 用于 Python 用于 Windows 子系统用于 Linux (WSL)。在左下角,我看到 python 版本是 3.6(这是我想要的):

但是,当我检查版本时:

print(sys.version)

我得到 2.7.17。为什么我不能使用 Python 3 以及如何将解释器切换到 Python 3.6.9?

有几种方法。最简单的方法是在您的脚本之上添加一个 shebang,如下所示:

#!/usr/bin/python3

此外,您 运行 代码是否使用了 python mycode.pypython3 mycode.py。它有所作为。

另一种方法是按照本教程安装和使用不同版本的python。 https://hackersandslackers.com/multiple-versions-python-ubuntu/

另一种方法是使用虚拟环境。这样您就可以在项目级别定义 python 版本。可能还有更多的方法。