VS code python debugger error with print statements

So when ever im trying to debug any Python script on VS code an that script has a print or input statement, it crashes an throws me an "AttributeError" that says 'NoneType' object has no attribute 'write', any ideas why this happens? i cant find any information on Google about it here is a screenshot in the error:Link to the screenshot and also here is my configuration file:

{
// Use IntelliSense para saber los atributos posibles.
// Mantenga el puntero para ver las descripciones de los existentes atributos 
// Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Python: Current File (Integrated Terminal)",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "program": "${file}",
        "console": "integratedTerminal"
    },
    {
        "name": "Python: Attach",
        "type": "python",
        "request": "attach",
        "port": 5678,
        "host": "localhost"
    },
    {
        "name": "Python: Django",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/manage.py",
        "console": "integratedTerminal",
        "args": [
            "runserver",
            "--noreload",
            "--nothreading"
        ],
        "django": true
    },
    {
        "name": "Python: Flask",
        "type": "python",
        "request": "launch",
        "module": "flask",
        "env": {
            "FLASK_APP": "app.py"
        },
        "args": [
            "run",
            "--no-debugger",
            "--no-reload"
        ],
        "jinja": true
    },
    {
        "name": "Python: Current File (External Terminal)",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "externalTerminal"
    }
]

}

Upvotes: 0

Views: 5397

Answers (2)

Jayanta
Jayanta

Reputation: 145

VSCODE working fine for me

a) Install VSCODE or upgrade to version 1.28.1 b) REFRESH Python Extension

If you face any issue like timeout etc read https://github.com/Microsoft/vscode-python/issues/2410 very carefully

Edit settings.json of python extension a) Disable Terminal: Activate Environment Activate Python Environment in Terminal created using the Extension.

b) enable Terminal: Execute In File Dir When executing a file in the terminal, whether to use execute in the file's directory, instead of the current open folder.

c) Remove pythonW and put python in Python Path Path to Python, you can use a custom version of Python by modifying this setting to include the full path.

Everything above from https://github.com/Microsoft/vscode-python/issues/2410

Though a happy ending I can foresee a future of unstable releases for a wonderful VSCODE and even better Python Extension

Upvotes: 1

Riv
Riv

Reputation: 335

An attribute error usually means that whatever object your working with is actually none. This can happen because something happened upstream or downstream of your call.

In the case of your single print statement, the only thing I can think of is perhaps it has something do so with double quotes.. It doesn't really make sense that double quotes would cause this but who knows.

what happens when you try

print('I will crash!!!')

If that still fails then I would say that perhaps vs is trying to write to a file, configuration, log, console or something else and is running into permission issues.

EDIT After looking closesr at your configuration files, I see you have two that start with

"name": "Python: Current File ....

So I rewrote your config file, it still includes the specific files that were named, and their configs, but I eliminated one of the current file entries and made it basic.

{
// Use IntelliSense para saber los atributos posibles.
// Mantenga el puntero para ver las descripciones de los existentes atributos 
// Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Python: Current File (External Terminal)",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "externalTerminal"
    },
    {
        "name": "Python: Attach",
        "type": "python",
        "request": "attach",
        "port": 5678,
        "host": "localhost"
    },
    {
        "name": "Python: Django",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/manage.py",
        "console": "integratedTerminal",
        "args": [
            "runserver",
            "--noreload",
            "--nothreading"
        ],
        "django": true
    },
    {
        "name": "Python: Flask",
        "type": "python",
        "request": "launch",
        "module": "flask",
        "env": {
            "FLASK_APP": "app.py"
        },
        "args": [
            "run",
            "--no-debugger",
            "--no-reload"
        ],
        "jinja": true
    }
]
}

I have it set up to use the external console (standard windows cmd). If you want to use the vs console replace

{
    "name": "Python: Current File (External Terminal)",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "externalTerminal"
},

with

{
    "name": "Python: Current File (Integrated Terminal)",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "program": "${file}",
    "console": "integratedTerminal"
},

Do NOT forget to save a copy of your old config file first. That way if VS freaks out from manually changing this file you can always revert back.

I am looking for the possibility that VS can't decide which terminal to output too, but at the same time you only get this while debugging so....

Now I did see a flag in the config for no debug but it was for a flask app.

Upvotes: 0

Related Questions