-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
launch.json environment variables not being passed to Python scripts #6986
Comments
Hi @duncanw 👋 thank you for reporting this issue! I can confirm that I can reproduce it in the following cases:
A few interesting notes:
|
Hi @kimadeline For code:
below configuration fails at first run, works for subsequent
but this configuration works for every run
|
Hi @kimadeline , the latest version still have this issue. detail info listed below:
still can not set env variables from launch.json, |
Hello @dehai, We haven't addressed this bug yet, please upvote the original comment to bump up its priority. According to the comment above yours it is possible to set environment variables in the {
"name": "Python: Current File 2",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {
"TEST": "1",
}
}, |
This is a decent broken existing feature nearly a year later and still no fix ? |
Major feature remains broken ? |
I'm also facing the same issue. |
I'm having the same issue on Windows 10 Pro using VSCode 1.56.2. When I run a test using 'Run Test' the environment variables are found, but when I run a test using 'Debug Test' the environment variables are not found. The following fails in debug, but passes with run test: def test_fails():
import os
env_keys = os.environ.keys()
assert "PYTHONDONTWRITEBYTECODE" in env_keys And my {
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": ".;tests",
"PYTHONDONTWRITEBYTECODE": "true"
},
}
],
} The following test always passes and shows that environment variables are normally found: def test_passes():
import os
env_keys = os.environ.keys()
assert "APPDATA" in env_keys |
If this won't be fixed, perhaps remove it from the documentation? |
VS Code 1.59.0 appears to prioritize loading environment variables from the |
Same issue here... Running on windows but with vscode remote to a redhat 7 machine.
returns the default value for |
Take a look here: https://stackoverflow.com/a/70748562/3223785 🤗 . |
The same problem exist on running .ipynb files (via interactive or jupyter extension) |
unless I'm missing something, I don't think it's the same issue, infact that's a feature request in the jupyter extension. |
Having this on 1.66.0 on Mac, the env variables actually never get passed. This is IMO pretty critical, making VSCode a no-go for my development. |
Regarding the main issue, we only accept variables as string. This is why in the case of If you want to use the variables in the test environment you have to add the purpose setting attribute as "debug-test" and if you want to use it in the terminal you must use ""debug-in-terminal". It is possible to set both values at once. For example:
|
I'm going to close the issue since the main problem has been resolved, if anyone has another bug, feel free to create another issue. |
Environment data
"python.jediEnabled"
set to; more info How to update the language server to the latest stable version #3977): Jedi Enabled = TrueExpected behaviour
Environment variables configured in launch.json should always be set when a python script is run or debugged.
Actual behaviour
Environment variables configured in launch.json are sometimes set when a python script is run or debugged. Sometimes they are not.
Steps to reproduce:
In my launch.json I have:
When debugging this, sometimes the command line includes the SANDBOX environment variable:
...but sometimes it doesn't, and the environment variable isn't available to the script:
If I edit and save weeklywip.py before running it seems more likely to include the environment variable as desired, but I haven't figured out a clear pattern. This only started happening since Visual Studio Code updated to version 1.37.0 on 2019-08-08.
The text was updated successfully, but these errors were encountered: