I'm trying to debug my Django project, but whenever I hit the play button on the run and debug window in VSCode, it thinks for a second, and then completely stops. My project runs completely fine when I run it with the "runserver" command.
I've tried restarting VSCode, and restarting my computer.
here is my launch.json 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: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\manage.py",
"args": [
"runserver",
"9000"
],
"django": true
}
]
}
Maybe this help :
Ctrl + Shift + P
Python: Select interpreter
Choose the right one
Related
I have this in my launch.json
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": "Python: Django",
"type": "python",
"request": "launch",
"python": "${command:python.interpreterPath}",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver"
],
"django": true,
"justMyCode": true
}
]
}
I want to change the bin used so that it doesn't use the normal bin of ubuntu but a virtual env (from pipenv shell).
does anyone now any configurations that i have to change to get this?
This configuration in the launch.json file can be used to specify the python interpreter path. "python": "${command:python.interpreterPath}".
For more configuration information, you can refer to this.
I try to debug my python script in VSCode, but it failed to stop at the breakpoint.
I click the debug button, but it seems like nothing happends. The codes never stop at my breakpoint!
Here's my launch.json. I use anaconda virtual envs as interpreter.
Please help me out, thanks!!!
{
// 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: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"stopOnEntry": true,
"pythonPath": "/home/linda/.conda/envs/py3/bin/python",
"justMyCode": false
}
]
}
I am writing my first library in Python, When developing I want my run code button in VS Code to always start running the code from the main.py file in the root directory. I have added a new configuration to launch.json however I seem to be unable to use this configuration as default. How can I do this/
You need to put the 'launch.json' under the '.vscode' folder inside your workspace. Then Run > Run Without Debugging (shortcut on windows CTRL+F5)
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": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/main.py",
"console": "integratedTerminal"
}
]
}
You can modify the launch.json with the below settings for key program. You may want to point program to the file which you want to execute. In the below case main.py is present in my workspace folder only. You can modify it as per your requirement.
{
// 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}/main.py",
"console": "integratedTerminal"
}
]
}
I found the right solution is to just change "program" in launch.json to:
"program": "main.py",
If trying to add the {workspaceFolder} it gives a FileNotFoundError.
In order to debug python scripts, I would like to run "source path_to/setup.bash" before python debugger begins. How should I to do so ? Thank you!
VSCode enables you to do this by setting a preLaunchTask in your launch.json
What you need is a task.json with a type set to shell. It looks something like this.
task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "prerun",
"type": "shell",
"command": "source hello.sh" // your shell command here
}
]
}
Remember the label "prerun". Now in your launch.json, alt Launch configuration, set this label as preLaunchTask like
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": "Python Experimental: Current File (Integrated Terminal)",
"type": "pythonExperimental",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"preLaunchTask": "prerun"
},
]
}
You can tailor your debug configuration for your needs. For the example above, it pre-launches hello.sh every time Python source file is the editor is in debug. Now switch to your Python code and continue debugging. Hope this helps.
I am struggling to configure VSCode on a Linux machine to start debugging a pyramid app (via pserve) without any success.
Any guidance will be much appreciated.
I was successful to debug my Pyramid application using the program option under Linux using this VS code launch.json 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: Pyramid Application",
"type": "python",
"request": "launch",
"program": "FullPathToExecutableFileHere",
"args": [
"param1",
"${workspaceFolder}/XXX.ini"
],
"pyramid": true,
"jinja": true
}
]
}
By giving the full path to the executable file, and providing the parameters in the args section.
I can now set a break point in any python source file code.
Don't forget to set the path of the python interpreter to the specific python virtual environment needed by your application using CTRL + Shift + P