Environment variables are incorrect
See original GitHub issueEnvironment data
- VS Code version: 1.36
- Extension version (available under the Extensions sidebar): Python 2019.9.34911; Remote SSH 0.45.6
- OS and version: macOS Mojave 10.14.6
- Python version (& distribution if applicable, e.g. Anaconda): 3.6.3 64 bit
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
- Relevant/affected Python packages and their versions:
- Jedi or Language Server? (i.e. what is
"python.jediEnabled"
set to; more info #3977): none
Expected behaviour
Expecting to be able to use my environment variables when running debug mode
Actual behaviour
environment variables are incorrect and do not match what I would normally get in the bash terminal
Steps to reproduce:
I’m trying to run debug via remote ssh extension. Using this launch configuration:
{
"name": "mia",
"type": "python",
"request": "launch",
"sudo": true,
"program": "/home/tdeng/a/bin/program.py",
"env": { "USER" : "tdeng"},
}
When I click debug “mia”, this statement returns the wrong value:
user = os.environ.get("USER")
as well as a variety of other environment variables. On my env, it user should equal “tdeng” my username, but instead, it returns “root”. I’ve set the “env” in launch.json but it doesn’t affect this (& I also would like to not use that since I want to keep my env variables in one place).
I’ve also set "terminal.integrated.inheritEnv": false
, but this did not affect this call either. When I run echo $USER
in the integrated terminal, i get “tdeng” for example.
In addition, if I were to run “/home/tdeng/a/bin/program.py” by clicking the “Run python file in terminal” button, it does work properly.
Posted here originally without it being resolved ): https://stackoverflow.com/questions/58115595/getting-incorrect-environment-variables-in-vs-code-debug-mode
Logs
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
XXX
Output from Console
under the Developer Tools
panel (toggle Developer Tools on under Help
; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging
)
XXX
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
@timdeng2324 Looks like we have a bug when using
"sudo": true
. We are not passing the environment variables correctly when using sudo.We do use
sudo -E
to spawn the launcher now, so this should be fixed.