You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 .env file 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
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
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 .env file.
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 .env file.
Renaming the .env file to .enva and repeating the steps does not lead to the environment variable being set, indicating that .env files 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?
The text was updated successfully, but these errors were encountered:
@fmardero This is likely coming from pythonTerminalEnvVarActivation feature, which is behind an experimental switch. You can turn it off by using this setting: "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"],
Does this issue occur when all extensions are disabled?: Yes
Steps to Reproduce:
Create a
.env
file in an empty project folder that includes an environment variable.Example:
Check if the environment variable exists before any further action:
set DEPLOY_ENV
Create a virtual environment in the project folder without activating it:
Verify the environment variable again as in step 2. It should not exist.
Activate the Python virtual environment manually:
source .venv/bin/activate
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
.env
file.Additional Observations
.env
file..env
file to.enva
and repeating the steps does not lead to the environment variable being set, indicating that.env
files 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
The text was updated successfully, but these errors were encountered: