I am using VSCode to debug my Python files. I have two scripts, let's say a.py and b.py. These two files work with differents args. I would like to configure launch.json in such a way that, if I run a.py, it should input its corresponding args and same for other files. However, there is no if statement in launch file. And if I write two configurations, it just runs them sequentially. What should my launch.json look like? Here is my first attempt.
{
// 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}/src/data_processing/main.py",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceRoot}"
},
"args": [
"/home/gokberk/Desktop/filtered_data",
"--gdc",
"gdc-client",
"--no-download",
"--manifest",
"/home/gokberk/Desktop/filtered_data/gdc_manifest.2021-05-26.txt",
"--source-slides-folder",
"/home/gokberk/Desktop/filtered_data"
]
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${WorkspaceFolder}/src/training.py",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceRoot}"
},
"args": [
"--input-data-folder",
"/home/gokberk/Desktop/filtered_data",
"--alpha",
"0.2",
"--beta",
"0.2",
"--max-bag-size",
"50",
"--underlying-model-type",
"resnet18",
"--pretrained",
"--no-download",
"--source-slides-folder",
"/home/gokberk/Desktop/filtered_data"
]
}
]
}
Related
I have installed the following task to compile my Go project following this blog post: https://robertbasic.com/blog/build-and-run-golang-projects-in-vs-code/
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build Go",
"type": "shell",
"command": "go build",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Now I can compile the project using Terminal>Run build task
For running and debugging, I have created:
launch.json:
{
// 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": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"cwd": "${workspaceRoot}",
"args": [],
"env": {}
}
]
}
But it does not work, I get the following message:
package .: no Go files in /usr/home/username/projects/my_app/.vscode
Process exiting with code: 1 signal: false
Visual Studio Code under FreeBSD12.1 (probably not relevant).
What do I have to do to get the program running when using F5/CTRL+F5?
Any tip including recommended help section or blog entry is welcomed.
Assuming my main package is at the root folder of the workspace, I always define the same .vscode/launch.json:
{
// 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": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"env": {},
"args": []
}
]
}
From there, I can press F5 from anywhere/any file, and the debug session simply starts.
I have a C file that I'm trying to debug but fail.
I'm using vscode on windows 10.
The file is quite large so I don't want to copy it here.
This is how my launch.json file looks in the .vscode folder in the folder that I'm working in:
{
// 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": "gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc.exe build active file"
}
]
}
This is how my tasks.json looks like in the same .vscode folder:
{
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
}
}
],
"version": "2.0.0"
}
when I press the "start debugging" button the screen freezes and the program stalls and then vscode crashes
I managed to find a solution, I deleted the old files, clicked debug, it wanted me to create a new configuration, chose gcc launch and then there was an option 'gcc.exe build and debug active file' , clicked it, and now everything works.
I've updated the content of the files above to how they look right now if anyone has the same issue in the future.
I have this launch.json running. Pressing F5, it first executes my Makefile (make) which produces the executable. I then simply like to run and get the terminal output until it's closed.
{
// 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": [
{
"type":"node",
"request": "launch",
"name": "Launch my app",
"program": "${workspaceFolder}\\myApp.exe",
"args": [
"-d",
"-v",
"-l",
"debug.log"
],
"preLaunchTask": "make",
"postDebugTask": "",
"cwd": "${workspaceFolder}"
}
]
}
While the tasks.json looks like this:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "make",
"type": "shell",
"command": "make",
"args": [],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "silent"
}
}
]
}
Sadly, VSCode always returns error
Cannot launch program 'C:\Users\Volker\src\myApp\myApp.exe'; setting
the 'outFiles' attribute might help.
I examined using ProcessExplorer and no one even tries to run the executable :-(
How to run the executable after it was build?
The omnisharp ReadMe says this:
Operating System Specific Configurations
If there specific commands
that need to be changed per operating system, you can use the fields:
'windows', 'osx', or 'linux'. You can replace any of the fields
mentioned above for the specific operating system.
This is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/TestConsole/bin/Debug/netcoreapp2.1/TestConsole.dll",
"args": [
"c:\\git\\core\\XunitTestLib\\Steps\\",
// "~/../../XunitTestLib/Steps"
],
"cwd": "${workspaceFolder}/TestConsole",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
},
]
}
When debugging I want to builds on Windows to start with the "args" entry which is uncommented, but on mac os I want it to start with the line which is commented out.
I am assuming that I would duplicate the configuration, once for Windows and mac, each, but this statement is confusing:
You can replace any of the fields mentioned above for the specific operating system.
It appears to be saying that I can replace "args" with "osx" but that obviously does not work.
How do I create a configuration for a target platform?
Turns out that targeting multiple platforms is a lot easier than I expected and is explained here with regards to the tasks.json file (but works just the same for launch.json).
My launch.json file adjusted for osx and windows would look like this:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/TestConsole/bin/Debug/netcoreapp2.1/TestConsole.dll",
"windows": {
"args": [
"c:\\git\\core\\XunitTestLib\\Steps\\"
]
},
"osx": {
"args": [
"~/../../XunitTestLib/Steps"
]
},
"cwd": "${workspaceFolder}/TestConsole",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
},
]
}
I seem to be missing something simple, but I can't figure out why I am unable to debug python using Visual Studio Code on Windows. I've tried setting up the debugger as shown by Microsoft, and this youtube video. I've done a clean install of Visual Studio Code (including the python extension) and Python 3.6. I have no other python versions installed. I keep getting the following errors in the Python Debugger:
cd "c:\Users\xxx\Documents\Python Scripts" ; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" "C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\python.exe" "C:\Users\xxx\.vscode\extensions\ms-python.python-2018.3.1\pythonFiles\PythonTools\visualstudio_py_launcher.py" "c:\Users\xxx\Documents\Python Scripts" 53746 34806ad9-833a-4524-8cd6-18ca4aa74f14 RedirectOutput,RedirectOutput "c:\Users\xxx\Documents\Python Scripts\.vscode\launch.json"
-bash: cd: c:\Users\xxx\Documents\Python Scripts: No such file or directory
env: ‘C:\\Users\\xxx\\AppData\\Local\\Programs\\Python\\Python36-32\\python.exe’: No such file or directory
It's complaining that it can't find the python.exe file, but it clearly can since VS code indicates that it's attached:
My launch.json file is the default, and I've tried all the configurations:
// 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}"
},
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"port": 3000,
"secret": "my_secret",
"host": "localhost"
},
{
"name": "Python: Terminal (integrated)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python: Terminal (external)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"debugOptions": [
"RedirectOutput",
"Django"
]
},
{
"name": "Python: Flask (0.11.x or later)",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "${workspaceFolder}/app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
]
},
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "module.name"
},
{
"name": "Python: Pyramid",
"type": "python",
"request": "launch",
"args": [
"${workspaceFolder}/development.ini"
],
"debugOptions": [
"RedirectOutput",
"Pyramid"
]
},
{
"name": "Python: Watson",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/console.py",
"args": [
"dev",
"runserver",
"--noreload=True"
]
},
{
"name": "Python: All debug Options",
"type": "python",
"request": "launch",
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"module": "module.name",
"env": {
"VAR1": "1",
"VAR2": "2"
},
"envFile": "${workspaceFolder}/.env",
"args": [
"arg1",
"arg2"
],
"debugOptions": [
"RedirectOutput"
]
}
]
}
Pylinting works fine, and I have not custom user settings in Visual Studio Code that are related to python. I've tried setting the complete file path to python.exe in settings.json but it makes no difference.
Any help is greatly appreciated. Thanks in advance
I had the same problem but finally got out of it after several adjustment to my settings.
make sure all other settings are in place as you've mentioned especially pythonPath in settings.json and also get "python" installed from the "extension" toolbar in VS code.
Simply change your debug configuration from "Python: Scripts" (or any other configuration you've selected previously) to "Python: Terminal(external)" and you are good to go!
I know, is a pain and I'm experiencing the same.
Apparently python.exe is executing correctly. You will keep seeing that banner because "This is necessary to bootstrap the debugger."
At least this is what Microsoft says.