Search code examples
pythonvisual-studio-codeprogram-entry-point

ImportError: can't find '__main__'


I'm trying to run a simple python program in microsoft visual code but, when I run the debugger I get the error ImportError: can't find 'main'. The code works fine if I run it in the terminal. This problem persists in every program I've created. The debugger worked fine the previous day but, now without me changing anything it is no longer working. I've tried reinstalling vs code and it had no effect. Can someone explain what I need to do?

Below is the code I used.

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


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

This is my launch file

{
    // 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"
        }
    ]
}

Solution

  • The problem at the value of program, it should be "${file}" instead of "${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"
            }
        ]
    }
    

    And it should be working now