Closed as not planned
Description
Behaviour
If I restart VS Code and modify the .env file, the new variable values from the .env file do not get applied to my FastAPI application.
Steps to reproduce problem:
- Go to the vs code settings tab and make sure that the Python:Env File field has the value
${workspaceFolder}/.env
- Create a .env file and add the variable
MY_VAR=1
. - Save the file.
- Close VS Code by right-clicking the VS Code icon and selecting "Quit".
- Open VS Code.
- Change the variable
MY_VAR
in the .env file toMY_VAR=2
. - Enter the command
echo $MY_VAR
in the terminal.
Description
I had to spend around two days troubleshooting an issue where VS Code automatically sets environment variables at terminal launch, causing non-obvious code behavior.
Considering that most of the audience are junior and middle-level developers, I believe many might face this problem. Is there a way to make this feature more explicit, such as prompting the user to enable or disable this setting? Or maybe we can make it opt-in instead of opt-out?
Diagnostic data
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
2024-07-23 15:10:15.854 [info] Experiment 'pythonCreateEnvOnPipInstall' is active
2024-07-23 15:10:15.854 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-07-23 15:10:15.854 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2024-07-23 15:10:15.854 [info] Experiment 'pythonTestAdapter' is active
2024-07-23 15:10:15.854 [error] Reading directory to watch failed [Error: ENOENT: no such file or directory, scandir '/Users/mun/code/test/.pixi/envs'
at Object.readdirSync (node:fs:1515:3)
at t.readdirSync (node:electron/js2c/node_init:2:11289)
at /Users/mun/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/out/client/extension.js:2:574598
at /Users/mun/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/out/client/extension.js:2:574789
at Array.map (<anonymous>)
at d.initWatchers (/Users/mun/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/out/client/extension.js:2:574507)
at async d.ensureWatchersReady (/Users/mun/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/out/client/extension.js:2:536827)] {
errno: -2,
syscall: 'scandir',
code: 'ENOENT',
path: '/Users/mun/code/test/.pixi/envs'
}
2024-07-23 15:10:15.854 [error] Dir "/Users/mun/code/test/.pixi/envs" is not watchable (directory does not exist)
2024-07-23 15:10:15.854 [info] Default formatter is set to charliermarsh.ruff for workspace /Users/mun/code/test
2024-07-23 15:10:15.854 [info] Python interpreter path: ~/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin/python
2024-07-23 15:10:15.860 [info] > pyenv which python
2024-07-23 15:10:15.860 [info] cwd: .
2024-07-23 15:10:16.393 [info] > pixi --version
2024-07-23 15:10:16.393 [error] [Error: spawn pixi ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:286:19)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)] {
errno: -2,
code: 'ENOENT',
syscall: 'spawn pixi',
path: 'pixi',
spawnargs: [ '--version' ]
}
2024-07-23 15:10:16.393 [warning] could not find a pixi interpreter for the interpreter at /Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin/python
2024-07-23 15:10:16.448 [info] > . ~/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/printEnvVariables.py
2024-07-23 15:10:16.448 [info] shell: zsh
2024-07-23 15:10:16.603 [info] > /usr/bin/python3 ~/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/printEnvVariables.py
2024-07-23 15:10:16.603 [info] shell: zsh
2024-07-23 15:10:16.680 [info] Setting environment variable MY_VAR in collection to 1 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:10:16.680 [info] Prepending environment variable PATH in collection with /Users/mun/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/deactivate/zsh:/Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:10:16.680 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:10:16.680 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to test-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:10:16.680 [info] Prepending environment variable PS1 in collection with test-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-07-23 15:10:16.680 [info] Send text to terminal: /usr/bin/python3 /Users/mun/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/printEnvVariablesToFile.py /Users/mun/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/deactivate/zsh/envVars.txt
2024-07-23 15:10:17.363 [info] Starting Pylance language server.
2024-07-23 15:10:20.290 [warning] could not find a pixi interpreter for the interpreter at /Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin/python
2024-07-23 15:10:20.294 [info] > . ~/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/printEnvVariables.py
2024-07-23 15:10:20.294 [info] shell: zsh
2024-07-23 15:10:20.322 [info] Setting environment variable MY_VAR in collection to 2 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:10:20.322 [info] Prepending environment variable PATH in collection with /Users/mun/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/deactivate/zsh:/Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:10:20.322 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:10:20.322 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to test-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:10:20.322 [info] Prepending environment variable PS1 in collection with test-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-07-23 15:14:44.889 [warning] could not find a pixi interpreter for the interpreter at /Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin/python
2024-07-23 15:14:44.889 [warning] could not find a pixi interpreter for the interpreter at /Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin/python
2024-07-23 15:14:44.905 [info] > . ~/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/printEnvVariables.py
2024-07-23 15:14:44.905 [info] shell: zsh
2024-07-23 15:14:44.905 [info] > . ~/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/printEnvVariables.py
2024-07-23 15:14:44.905 [info] shell: zsh
2024-07-23 15:14:44.934 [info] Setting environment variable VSCODE_L10N_BUNDLE_LOCATION in collection to {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:14:44.934 [info] Prepending environment variable PATH in collection with /Users/mun/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/deactivate/zsh:/Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:14:44.934 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:14:44.934 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to test-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:14:44.934 [info] Prepending environment variable PS1 in collection with test-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-07-23 15:14:44.935 [info] Setting environment variable VSCODE_L10N_BUNDLE_LOCATION in collection to {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:14:44.935 [info] Prepending environment variable PATH in collection with /Users/mun/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/deactivate/zsh:/Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:14:44.935 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:14:44.935 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to test-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 15:14:44.935 [info] Prepending environment variable PS1 in collection with test-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-07-23 15:14:45.129 [info] Discover tests for workspace name: undefined - uri: /Users/mun/Library/Application Support/Code/User/settings.json
2024-07-23 16:52:09.240 [warning] could not find a pixi interpreter for the interpreter at /Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin/python
2024-07-23 16:52:09.250 [info] > . ~/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/printEnvVariables.py
2024-07-23 16:52:09.250 [info] shell: zsh
2024-07-23 16:52:09.296 [info] Setting environment variable VSCODE_L10N_BUNDLE_LOCATION in collection to {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 16:52:09.296 [info] Prepending environment variable PATH in collection with /Users/mun/.vscode/extensions/ms-python.python-2024.10.0-darwin-arm64/python_files/deactivate/zsh:/Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 16:52:09.296 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/mun/Library/Caches/pypoetry/virtualenvs/test-3KCHDMEl-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 16:52:09.296 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to test-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-07-23 16:52:09.296 [info] Prepending environment variable PS1 in collection with test-py3.12 {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-07-23 17:09:14.521 [info] Discover tests for workspace name: test - uri: /Users/mun/code/test/config.py
2024-07-23 17:09:20.298 [info] Discover tests for workspace name: test - uri: /Users/mun/code/test/config.py
Laubeee and oezeb
Metadata
Metadata
Assignees
Labels
Needs assignment to the proper sub-teamNeeds assignment to the proper sub-team