【问题标题】:Im Trying To Run Python On Visual Studio Code But am Facing An File Not Found Error我试图在 Visual Studio 代码上运行 Python,但遇到文件未找到错误
【发布时间】:2021-01-18 17:27:36
【问题描述】:

我安装了 python 并在 PyCharm 中使用了几个星期,由于某些功能,我想切换到 Visual Studio Code。我创建了一个文件并将其从右下角设置为 Python,当我尝试运行和调试时,它显示一条错误消息,显示“FileNotFoundError: [Errno 2] No such file or directory: 'C:\Untitled-1' PS C:>“

【问题讨论】:

  • 运行前保存
  • 我尝试保存它,但没有成功。所以我卸载了 Python、Visual Studio 并重新安装了它们,但现在当我只写 print("Hello World") 时,它会显示“SyntaxError: invalid syntax”
  • 也许尝试将默认 shell 切换到 Command Prompt
  • 成功了,非常感谢!
  • @JacobK 嘿,你能把这个作为答案发布,而不是评论,我需要以答案格式来批准。

标签: python visual-studio-code error-handling pip


【解决方案1】:

我们可以在 VS Code 中使用 cmd 终端和 powershell 终端。

当我们运行代码,VSCode终端在Python交互窗口时,终端显示:“SyntaxError: invalid syntax”:(因为Python交互窗口识别Python代码,运行按钮是执行带有路径的命令.)

解决方案:

  1. 点击VS Code右上角绿色的运行按钮:

  2. 或者在终端输入“Python”进入Python交互窗口,然后在终端输入代码:

关于在 VS Code 中使用 Python,您可以参考此文档:Python in VS Code

【讨论】:

    猜你喜欢
    • 2021-04-01
    • 2020-11-26
    • 2023-01-24
    • 2023-02-19
    • 2017-01-02
    • 2020-07-09
    • 2021-08-07
    • 1970-01-01
    • 2021-04-03
    相关资源
    最近更新 更多