【问题标题】:ImportError: can't find '__main__'导入错误:找不到“__main__”
【发布时间】:2020-10-24 16:27:18
【问题描述】:

我正在尝试在 microsoft 可视化代码中运行一个简单的 python 程序,但是,当我运行调试器时,我收到错误 ImportError: can't find 'ma​​in'。如果我在终端中运行代码,它可以正常工作。这个问题在我创建的每个程序中都存在。调试器前一天工作正常,但现在没有我改变任何东西,它就不再工作了。我试过重新安装vs code,但没有效果。有人可以解释我需要做什么吗?

下面是我使用的代码。

t = []
for x in range(0,5):
    t.append(["x"] *5)


def review(t):
    for row in t:
        print("".join(row))
review(t)

这是我的启动文件

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "Python: Current File ",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}",
            "console": "integratedTerminal"
        }
    ]
}

【问题讨论】:

标签: python visual-studio-code main


【解决方案1】:

program值的问题,应该是"${file}"而不是"${workspaceFolder}"

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "Python: Current File ",
            "type": "python",
            "request": "launch",
            "program": "${file}", // new here
            "console": "integratedTerminal"
        }
    ]
}

它现在应该可以工作了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-26
    • 1970-01-01
    • 2021-12-21
    • 2021-01-02
    • 2021-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多