【问题标题】:Visual Studio Code TerminalVisual Studio 代码终端
【发布时间】:2019-04-03 13:10:35
【问题描述】:

当我尝试使用打印命令在终端中运行 Python 代码时,没有任何反应。当我在终端本身尝试test.py 命令时,下面复制的文本就是输出。

请协助如何让终端打印我的代码。

E:\Kath\Documents\blockchain> test.py
test.py : The term 'test.py' is not
recognized as the name of a cmdlet, function,
script file, or operable program. Check the
spelling of the name, or if a path was
included, verify that the path is correct and
try again.
At line:1 char:1
+ test.py
+ ~~~~~~~
    + CategoryInfo          : ObjectNotFound:
    (test.py:String) [], CommandNotFoundExce
  ption
    + FullyQualifiedErrorId : CommandNotFound
   Exception

【问题讨论】:

  • python test.py ?
  • 谢谢!尝试了这个,它再次输出相同的消息。还有其他想法吗?

标签: python terminal visual-studio-code


【解决方案1】:

打开 VS Code 后,通过打开命令面板 (Ctrl+Shift+P) 选择 Python 3 解释器,开始输入 Python: Select Interpreter 命令进行搜索,然后选择命令. 如果可用,您还可以使用状态栏上的选择 Python 环境选项。 现在,创建一个新文件,并使用扩展名 .py 保存它。完成此操作后,在工作区中编写所需的代码。然后右键单击工作区 --> 在终端中运行 Python 文件。 这将运行选定的文件。 希望这个解决方案有所帮助。

【讨论】:

    【解决方案2】:

    在“终端”中,您会看到本质上是常规命令提示符,而您的命令解释器是 PowerShell。

    因此,要执行 python 脚本,您应该将其运行为:

    python test.py 
    

    python3 test.py
    

    或类似的,取决于你的 python 可执行文件。

    由于 Powershell 是您在 Visual Studio Code 中的默认命令外壳,如果“.py”扩展名是用 Python 注册的,您可以尝试:

    .\test.py
    

    如果您使用虚拟环境,请确保选择正确的 Python 解释器。

    【讨论】:

    • 感谢您的信息!我已经尝试了提供的两个选项,并且都再次返回了相同的输出消息。我在哪里检查 python 解释器?
    • 谢谢...这很有用,但仍然没有解决我的问题。我的代码仍然无法在终端中运行,我似乎没有任何 python 解释器的选项。这是我应该下载的东西吗?
    • 是的。 :) 我假设你已经安装了 python。首先从 python.org 下载适用于 Windows 的 Python 安装程序。试试这个链接python.org/downloads
    • 哦,是的,我已经下载了 Visual Studio 代码......这是我编写代码的地方和我无法工作的终端之间的连接
    • 我之前的评论是关于安装 Python,而不是 Visual Studio 代码。你安装了java Python吗?如果没有,请从 python.org 下载。
    猜你喜欢
    • 2021-04-10
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    相关资源
    最近更新 更多