question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Environment variables are incorrect

See original GitHub issue

Environment 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 (ViewOutput, 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:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
karthiknadigcommented, Oct 10, 2019

@timdeng2324 Looks like we have a bug when using "sudo": true . We are not passing the environment variables correctly when using sudo.

0reactions
int19hcommented, Nov 9, 2020

We do use sudo -E to spawn the launcher now, so this should be fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems with Environment Variables
Environment variable is not set. If the error message states that the environment variable is not set, IT MEANS PRECISELY THAT ! The...
Read more >
Resolving incorrect environment variables for BACKUP DB ...
Many of the BACKUP DB or RESTORE DB processing problems are as a result of incorrectly set DSMI_CONFIG, DSMI_DIR, or DSMI_LOG environment variables....
Read more >
User variables are not resolved correctly in Windows
Fixes an issue in which user variables are not resolved correctly in Windows 8.1, Windows Server 2012 R2, Windows 7 SP1, or Windows...
Read more >
The incorrect setting of the Environment variables prevents the ...
If the Environment variables is configured incorrectly , i.e. when the Oracle BI installation is not done to the C:\ drive, but another...
Read more >
PATH variable set incorrectly - Stack Overflow
Go to My Computer > Right click> Properties > Advanced System Settings > Advanced Tab > Environment Variables. Here you can see the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found