'python vscode environment variables not available
I have attempted to follow the directions for environment variables in my project and thought I was doing the correct thing but it does not appear to be working when debugging my python code in vscode.
I have a launch.json for a project in .vscode/
{
// 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,
"envFile": "${workspaceFolder}/dev.env"
}
]
}
and a dev.env file in my project root
PYTHONUNBUFFERED=1
PASSWORD=abc123
DEBUG_SSO=user.name
CELERY_DEBUG=True
SEND_MAIL=True
when I hit a breakpoint and do "os.getenv('PASSWORD')" it returns None, even though the variable is set in dev.env.
Any idea what is wrong with this configuration?
Solution 1:[1]
This may be due to the relative path being unrecognized. Add this line to the file "launch.json" : "cwd": "${fileDirname}"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | MingJie-MSFT |