
[英]VS Code and python debugger returning error but can run in the terminal
[英]VS code python debugger error with print statements
因此,当我尝试在VS代码上调试任何Python脚本时,该脚本具有print或input语句时,就会崩溃,并抛出“ AttributeError”,提示“ NoneType”对象没有属性“ write”,为什么会发生这种情况? ? 我在Google上找不到关于它的任何信息,这是错误中的屏幕截图 : 链接到屏幕截图 ,这也是我的配置文件:
{
// 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"
}
]
}
VSCODE对我来说很好
a)安装VSCODE或升级到版本1.28.1 b)刷新Python扩展
如果您遇到超时等问题, 请仔细阅读https://github.com/Microsoft/vscode-python/issues/2410
编辑python扩展的settings.json a) 禁用终端:激活环境在使用扩展创建的终端中激活Python环境。
b) 启用终端:在文件目录中执行在终端中执行文件时,是否在文件目录中使用执行,而不是在当前打开的文件夹中使用。
c)删除pythonW并将python放入Python路径Python的路径中,可以通过修改此设置以包含完整路径来使用Python的自定义版本。
以上一切均来自 https://github.com/Microsoft/vscode-python/issues/2410
尽管结局不错,但我可以预见到发行不稳定版本的未来,以实现出色的VSCODE甚至更好的Python扩展
属性错误通常意味着您使用的任何对象实际上都不存在。 之所以会发生这种情况,是因为您的通话上游或下游发生了某些事情。
就您的单行打印语句而言,我唯一想到的可能是它带有双引号。.用双引号引起这一点并没有什么意义,但谁知道。
尝试时会发生什么
print('I will crash!!!')
如果仍然失败,那么我想说的是vs正在尝试写入文件,配置,日志,控制台或其他内容,并且遇到了权限问题。
编辑在您的配置文件中查看closesr之后,我看到您有两个以
"name": "Python: Current 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 (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
}
]
}
我已将其设置为使用外部控制台(标准Windows cmd)。 如果要使用vs控制台,请更换
{
"name": "Python: Current File (External Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
},
同
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"console": "integratedTerminal"
},
不要忘了先保存旧配置文件的副本。 这样,如果VS无法手动更改此文件,则可以随时还原。
我正在寻找VS无法确定也要输出哪个终端的可能性,但同时您只能在调试时得到它。
现在,我确实在配置中看到一个标志,没有调试,但它是针对flask应用程序的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.