I have a fairly large python/c++ program that runs as follow:
The set_env.sh script modifies the PYTHONPATH and does all sort of export in order to point to the right c++ program. When running these two commands in the terminal, that works just well, however, using the debugger breaks it all.
I try running ". set_env.sh -option A -option B" in preLaunchTask but it seems the debugger can't see the new PYTHONPATH.
How can I make the debugger run the the set_env and consider the new PYTHONPATH ?
Inspired by my current area of work - which involved Python.
https://code.visualstudio.com/docs/python/debugging
import os
for key in os.environ.keys():
print(f"{key}={os.environ.get(key)}")
After doing a F5 in VS Code with a file containing the above snippet:
After receiving a comment I think the OP wants to run a script before debugging the Fask application. The steps that worked for me are below.
I ended up with the following files:
dosomething.ps1
(my custom script which I intend to launch before every debug session)task.json
(launch dosomething.ps1)launch.json
by linking it with the task in task.json
Write-Host "Inside do something"
Write-Host "The value of the environment variable TEMP is $env:TEMPcls"
Write-Host "The current path of the script is $PSScriptroot"
{
"version": "2.0.0",
"tasks": [
{
"label": "my script task",
"type": "shell",
"windows": {
"command": "pwsh -f dosomething.ps1"
},
"problemMatcher": []
}
]
}
In my team, we place all confidential variables in a .env
file and add the file to .gitignore
. As per design of VS Code, it will look for a .env
file in the root of the current workspace and load those variables before launching your Python script. Please refer documentaion from MS here: https://code.visualstudio.com/docs/python/environments
By default, the Python extension looks for and loads a file named .env in the current workspace folder, then applies those definitions. The file is identified by the default entry "python.envFile": "${workspaceFolder}/.env" in your user settings (see General Python settings). You can change the python.envFile setting at any time to use a different definitions file