VSCode Pyramid Debug - python

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

Related

"Timed out waiting for launcher to connect" preventing debugger from launching

I am trying to run a debugger, but it consistently sends back a message with the above quote and an option to open the 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: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
This is what my launch.json file looks like. I've currently tried:
Deleting and recreating the launch.json file
Altering the launch.json file according to Time out waiting for launcher to connect in VS code
Going back to an earlier version of the python extension
Uninstalling all of my python extensions and reinstalling them
My Python version is currently 3.9.0 according to the text at the bottom right corner of the VScode window. The rest of VScode with Python appears to work as expected.
This is what my terminal looks like:
PS C:\Users\alexs\Documents\BEng\Software 1\Formative Assessment\2\SOF1-2022-23-EvenYears-Formative-2\ClosedExamination> \Users\alexs\AppData\Local\Microsoft\WindowsApps\python3.7.exe' 'c:\Users\alexs\.vscode\extensions\ms-python.python-2022.20.2\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '57863' '--' 'c:\Users\alexs\Documents\BEng\Software 1\Formative Assessment\2\SOF1-2022-23-EvenYears-Formative-2\ClosedExamination\test_question_4.py'
>> 'C:

Debugger does not start in VSCode for Django

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

How to debug remote python code from local windows vs code

I want to debug python code (on remote linux) in local windows with VS code.
I did as follows:
In windows VS code, I can open remote linux python project using SSH.
Installed python debug tool ptvsd both in windows and remote linux.
Add code below in python project:
import ptvsd
ptvsd.enable_attach(address = ('$linux_ip', $port))
ptvsd.wait_for_attach()
Project 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: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "$linux_ip",
"port": $port
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "$my_real_linux_ws"
}
]
}
]
}
Start run in remote linux.
Add break points in vs code, and run -> start debugging, then hit an issue as follows. I am confused that test.py is not in dir /c4_working/test.py but in dir /c4_working/python_code/test.py. And this file actually exists. So I am not sure why it would want to find the file in dir /c4_working/test.py? How would I fix it?
Have you read the documentation before asking your question?
A specially this part:
PS: strongly recommend to check remote-pdb as well.
Fixed this issue after creating a new launch.json file for this dir /c4_working/python_code.

How setup lauch.json for VS Code so I can use other folders/files in the current working directory?

I'm trying to write python code that needs to read files in the same current working directory. I'm new using VS code so I don't really know how to set it up have the launch.json the following way, but it still doesn't read other files in the same cwd. HELP :'v
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": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}"
}
]
}
${cwd} - the task runner's current working directory on startup
The default setting of 'cwd' is the "${workspaceFolder}". In VSCode, the relative path depends on the setting parameter 'cwd', unless you use an absolute path. It doesn't care the relative path to your python file, it just cares the relative path to 'cwd'.

python scripts debug in ROS with Visual Studio Code

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.

Categories

Resources