As I can't give input in the debug console, I'm trying to run the debugger in External terminal in VS Code.
This is the part of launch.json config file for external terminal.
{
"name": "Python: Terminal (external)",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "",
"console": "externalTerminal",
"env": {},
"externalConsole": true,
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit"
]
},
I added the "externalConsole": true part as they said here and I tried with or without that statement.
I get this error,
Debug adapter process has terminated unexpectedly
I tried the docs and the IntelliSense in the json file, but I can't understand and get it to work.
Adding "console": "externalTerminal", to the debug configuration file worked fine on Linux!
I am using windows, however, this should fix your problem.
"name": "Python: Terminal (external)",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "C:/Users/Zac/Anaconda3/python.exe",
"program": "${file}",
"cwd": "",
"console": "externalTerminal",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
},
You need to correctly add a path to your python.exe location in the "pythonPath" line.
Also, take out the "WaitOnAbnormalExit" and "WaitOnNormalExit" from "debugOptions" and just use "RedirectOutput". Remove "externalConsole": true from the code.
Everything else should stay the same.
Hope that helps.
Cheers.
Also remember to put correct value for external terminal location in :
terminal.external.windowsExec
Related
So after much searching I found a way to get gunicorn to play nice with vscode using the following launch.json
"version": "0.2.0",
"configurations": [
{
"name": "Python: Run Debug",
"cwd": "${workspaceFolder}/dir/dir2",
"type": "python",
"request": "launch",
"program": "/Users/me/.virtualenvs/dir/bin/gunicorn",
"args": ["--bind 0.0.0.0:6543", "-w=1", "--paste=local.ini" ],
"console": "integratedTerminal",
"justMyCode": false,
"purpose": ["debug-in-terminal"],
"gevent": true,
"env": {
"GEVENT_SUPPORT": "True",
"PYTHONUNBUFFERED":"1",
"OBJC_DISABLE_INITIALIZE_FORK_SAFETY":"YES",
"PYDEVD_LOAD_NATIVE_LIB": "0",
"PYDEVD_USE_CYTHON":"0"
}
}
]
}
Now this makes the server run but it outputs no variables, it doesn't stop at any breakpoints, and I can't watch anything. Basically, the whole left pane is completely empty.
Has anyone dealt with this successfully before?
I have a project and am trying to debug my main.py. I am really confused why I am getting the following error from the imports at the top of my file (only) when running the debugger:
Exception has occurred: ModuleNotFoundError
No module named 'bbb'
File "/Users/maxepstein/myproject/bbb/train/__main__.py", line 8, in <module>
from bbb.mysubfolder.myfile import myfunction
My project folder structure, as shown by these print statements (as shown by the debugger) confirms my 'bbb' module exists, and has an __init__.py:
import os
print(os.getcwd())
print(os.listdir())
print(os.listdir('bbb'))
/Users/maxepstein/myproject
['requirements.txt', 'bbb', 'resources', '__init__.py', 'readme.md', 'results', '.gitignore', '.git', '.vscode', 'bbenv']
['config', 'tests', '__init__.py', 'utils', 'predict', 'train']
I'm trying to debug as "debug current file - integrated terminal", below is the applicable debug settings from my debug settings.json. After searching online, I really thought adding "cwd": "/Users/maxepstein/myproject" below would be my solution but it hasn't helped.
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "/Users/maxepstein/myproject"
}
A simple workaround to the bug mentioned by #BrettCannon is to add the following env entry to the launch.json configuration:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": { "PYTHONPATH": "${workspaceRoot}"}
}
]
}
Had the same problem when importing from a nested directory, and fixed it by appending to the env variable PYTHONPATH:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"env": {
"PYTHONPATH":"${PYTHONPATH}:/home/maxepstein/myproject/"
}
}
]
}
When I am debugging a Python module in VS Code I use the Module debug configuration instead of the Current File one. For you it might look like this:
{
"name" : "Python: Module",
"type" : "python",
"request": "launch",
"module": "bbb",
"args": []
}
See the documentation https://code.visualstudio.com/docs/python/debugging
Also, in VS Code, these steps will auto-populate these settings for you:
Debug -> Add Configuration -> Python: Module
In my case, I quickly fixed it selecting the right interpreter:
You can use the current file debug configuration. In the file you're debugging that's importing the modules add the full path to the modules you're trying to import to your system path.
sys.path.append('/Users/my_repos/hw/assignment')
import src.network as network
The module here is src, located in the assignment directory.
I run the debugger from VS Code.
My structure in VS code:
myproject
+vscode
+---launch.json
|
+src
+---test/
+------MainTest.py
+---Main.py
the launch.json that saved me:
{
// 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}",
"env": {"PYTHONPATH": "${workspaceRoot}:src"},
"console": "integratedTerminal"
}
]
}
I am trying to debug this very simple code, but it doesn't do anything after I input a number.
import math
pi = math.pi
r = int(input('Enter number:'))
circum = 2 * pi * r
print(circum)
But for the simple and complicated codes which don't contain input(), I can debug them very easily. When I debug this code in Spyder, it does perfectly, but not in Visual Studio Code. I really need help
PS. I have already configured launch.json
I got it to work when i switched to use the "Integrated Terminal/Console" debug configuration.
{
"name": "Integrated Terminal/Console",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "",
"console": "integratedTerminal",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit"
]
},
https://donjayamanne.github.io/pythonVSCodeDocs/docs/debugging_terminal-console-apps/#Option-1
I can't figure out why vscode debugger is not working. I tried everything, but the breakpoints are still not working. Has anyone had a similar problem, and solved it?
My lauch.json file just for reference:
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config.python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceRoot}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
"stopOnEntry": true,
Set this to false
i have recently installed visual studio code, and i added python extension, and i have added the python path to tasks.json and settings.json and launch.json i can debug but i can't input data while the code is running, i have tried Integrated Terminal/Console but it's not working, this is the output :
C:\Users\Mugiwara303\Documents\VSCpython>cd null && cmd /C "set "PYTHONIOENCODING=UTF-8" && C:\Users\Mugiwara303\AppData\Local\
Programs\Python\Python35-32\python.exe C:\Users\Mugiwara303\.vscode\extensions\donjayamanne.python-0.5.5\pythonFiles\PythonTool
s\visualstudio_py_launcher.py null 57138 34806ad9-833a-4524-8cd6-18ca4aa74f14 WaitOnAbnormalExit,WaitOnNormalExit c:\Users\Mugi
wara303\Documents\VSCpython\.vscode\main.py "
The system cannot find the path specified.
finally i have fix it! "cwd": "${workspaceRoot}", instead of "cwd": "null",
{
"name": "Integrated Terminal/Console",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "C:\\Users\\Mugiwara303\\AppData\\Local\\Programs\\Python\\Python35-32\\python.exe",
"program": "${file}",
"cwd": "${workspaceRoot}",
"console": "integratedTerminal",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit"
]
},