Skip to content

launch.json environment variables not being passed to Python scripts #6986

Closed
@duncanw

Description

@duncanw

Environment 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 How to update the language server to the latest stable version #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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-debuggingbugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions