-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.95.3 (Universal)
- OS Version: MacOS Sequoia 15.0.1 (24A348) | Also tested on Windows 11 Pro (22H2)
Steps to Reproduce:
-
Create a
.envfile in an empty project folder that includes an environment variable.
Example:DEPLOY_ENV=dev
-
Check if the environment variable exists before any further action:
- On Linux/MacOS:
echo $DEPLOY_ENV
- On Windows:
set DEPLOY_ENV
- On Linux/MacOS:
-
Create a virtual environment in the project folder without activating it:
python3 -m venv .venv
-
Verify the environment variable again as in step 2. It should not exist.
-
Activate the Python virtual environment manually:
- On Linux/MacOS:
source .venv/bin/activate - On Windows:
.venv\Scripts\activate.bat
- On Linux/MacOS:
-
Check the environment variable again as in step 2. It should still not exist.
-
Select the virtual environment's Python interpreter in VS Code using the Command Palette.
-
Open a new integrated terminal window in VS Code.
-
Check the environment variable again as in step 2. This time, the variable exists and matches the value defined in the
.envfile.
Additional Observations
- If VS Code automatically detects the virtual environment and you then open a new terminal window, the same behavior occurs: the environment variable is set according to the
.envfile. - Renaming the
.envfile to.envaand repeating the steps does not lead to the environment variable being set, indicating that.envfiles specifically are read and applied.
Summary
It seems that selecting the Python interpreter associated with the virtual environment in VS Code automatically reads and exports the variables defined in a .env file. However, I could not find any documentation describing this behavior.
Questions/Clarifications
- Is this behavior intended or a side effect of VS Code's environment handling?
- If intended, could you provide documentation or guidance on how this behavior can be controlled or disabled?