Search code examples
pythonvisual-studio-codepython-extensions

How does VSCode's Python Extension handle a missing .env file?


I'm trying to troubleshoot an issue with VSCode's Python extension loading the wrong version of Python and I'd like to rule out incorrect environment variables being an issue.

In the Python Extension's settings there is the following option:

Python: Env File option in VSCode's Python extension settings.

My workspace doesn't contain a ./env file. What will VSCode's Python extension default to in this situation?


Solution

  • Take a look at the official VSCode documentation on Environment Variable Definition Files. I think the following section is relevant to your question:

    VSCode's Environment Variable Definition file section.

    As you can see, the .env file is there to set the value of any pre-existing environment variables.

    If the file existed but had no key-value pairs in it then the environment variables would be unchanged from the system's own definitions.

    Therefore, if .env doesn't exist, the environment variables will be defined by your system. This is the default behaviour.