I'm using .env in a Python project, with python-dotenv, but it seems like VSCode automatically loads the environment variables from the .env.
Unfortunately, VSCode does not seem to update the environment variables when I modify the .env file, causing the Python program to run on old environment vars.
Restarting VSCode / opening new integrated terminals does not seem to help. It looks as if it caches the .env somewhere, and reloads it from cache, without removing the cache when the original file is updated.
Output of /usr/bin/env together with .env file:
Output of Help: About:
Version: 1.84.0-insider (Universal)
Commit: f1c3b1dcf85e3b6ddb24b7dce0e4b122e8ce6233
Date: 2023-10-17T05:38:23.658Z
Electron: 25.8.4
ElectronBuildId: 24154031
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin x64 22.6.0
Python extension version v2023.19.12931008
.
I'm not sure how your Python code is getting environment variables, but this is how I usually do.
.env
config.py
main.py
I personally like separated file for configurations (easier to debug). Let me know if this helped, if not, this might help