VSCode 运行 Python 2 而不是 3 [英] VSCode running Python 2 instead of 3

查看:118
本文介绍了VSCode 运行 Python 2 而不是 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VSCode 中使用 Python,如果我使用 Cmd+Shift+P 并键入 Run Code,它会使用 Python2 运行代码,即使我已将其指定为使用 Python3.我已阅读本教程:如何强制 VSCode 使用 Python 3而不是 Python 2?但我不明白如何改变它.(我不能发表评论,因为我没有足够的声誉耶)有人可以帮忙吗?谢谢!

I am using Python with VSCode, and if I use Cmd+Shift+P and type Run Code, it runs the code with Python2 even though I have specified it to use Python3. I have read this tutorial: How to force VSCode to use Python 3 instead of Python 2? but I do not understand how to change it. (and I can't comment because I don't have enough reputation yay) Could anyone help? Thanks!

也许这可能与底部的迷你终端运行python -u"而不是python3 -u"有关?有人知道怎么改吗?

Maybe it could be related to the fact that the mini terminal at the bottom runs "python -u " instead of "python3 -u "? Does anyone know how to change that?

推荐答案

请注意命令 Run Code 不是由 Python Extension for VS Code 提供,而是由扩展 代码运行器.它们是两个独立的扩展.您需要将该扩展配置为指向您选择的 Python Interpter.IE.根据主页上的文档,您必须更新设置:

Please note the command Run Code is not provided by the Python Extension for VS Code, instead it is provided by the extension Code Runner. They are two separate extensions. You'll need to configure that extension to point to the Python Interpter you have chosen. I.e. as per their docs on the home page you have to update the settings:

{
    "code-runner.executorMap": {
        "python": "<fully qualified path>",
    }
}

或者您有另一种解决方案,即使用命令Python:在终端中运行 Python 文件.这不依赖于 Code Runner 扩展,而是 Python 扩展 的一部分,因此使用您选择的解释器.

Or you have another solution, that's to use the command Python: Run Python file in Terminal. This does not rely on the Code Runner extension and is part of the Python Extension hence using the interpreter you have selected.

这篇关于VSCode 运行 Python 2 而不是 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆