launch.json environment variables not being passed to Python scripts
See original GitHub issueEnvironment data
- VS Code version: 1.37.1
- Extension version (available under the Extensions sidebar): 2019.8.30787
- OS and version: Windows 10
- Python version (& distribution if applicable, e.g. Anaconda): 2.7.13
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): virtualenv
- Jedi or Language Server? (i.e. what is
"python.jediEnabled"
set to; more info #3977): Jedi Enabled = True
Expected 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:
"configurations": [
{
"name": "Python: current jobs",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/beany/beany/util/reporting/weeklywip.py",
"console": "integratedTerminal",
"env" : {
"SANDBOX" : 1
}
}
]
When debugging this, sometimes the command line includes the SANDBOX environment variable:
PS D:\workspace\vscode> cd 'd:\workspace\vscode'; ${env:SANDBOX}='1'; ${env:PYTHONIOENCODING}='UTF-8'; ${env:PYTHONUNBUFFERED}='1'; & 'd:\workspace\vscode\beany\env\Scripts\python.exe' 'c:\Users\dunca\.vscode\extensions\ms-python.python-2019.8.29288\pythonFiles\ptvsd_launcher.py' '--default' '--client' '--host' 'localhost' '--port' '50043' 'D:\workspace\vscode/beany/beany/util/reporting/weeklywip.py'
…but sometimes it doesn’t, and the environment variable isn’t available to the script:
PS D:\workspace\vscode> & 'd:\workspace\vscode\beany\env\Scripts\python.exe' 'c:\Users\dunca\.vscode\extensions\ms-python.python-2019.8.29288\pythonFiles\ptvsd_launcher.py' '--default' '--client' '--host' 'localhost' '--port' '50035' 'D:\workspace\vscode/beany/beany/util/reporting/weeklywip.py'
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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:43
- Comments:17
Top Results From Across the Web
Environment variables in launch.json not recognized when ...
However, when I run my Flask application from the run.py script, it doesn't seem to recognize the variables. Although the "FLASK_DEBUG" is set ......
Read more >Debugging configurations for Python apps in Visual Studio Code
If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on...
Read more >Run/debug configurations | PyCharm Documentation - JetBrains
Learn how to use run configurations to run/debug your code in PyCharm with various startup properties.
Read more >Working with Environment Variables in Python - Twilio
A variable that is set in this way will be passed on to any programs or scripts that you start from this terminal...
Read more >Debug Python code - Visual Studio (Windows) - Microsoft Learn
The value may be useful for launching your script with a non-standard interpreter. Environment Variables, In this multi-line text box, add ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a decent broken existing feature nearly a year later and still no fix ?
If this won’t be fixed, perhaps remove it from the documentation?