Skip to content

Commit 195d821

Browse files
authored
feat: add blog post about vscode Python extension (#87)
1 parent bed1ddf commit 195d821

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
date:
3+
created: 2025-04-01
4+
---
5+
# Stopping VSCode Python Extension from Changing your Terminal Environment
6+
7+
I have tripped over an outdated environment variable a few times when running Python from within `vscode`.
8+
And I finally figured out what caused it.
9+
10+
We store our environment variables in a `.env` file that is then used by our *Django* application.
11+
We use the [django-environ](https://github.com/joke2k/django-environ) package for this.
12+
During development, this file is loaded on startup.
13+
When deployed, we provide the file via `env_file` in the compose file.
14+
15+
What happened in `vscode` is that when a value in `.env` changed, running something, such as `pytest`, would not see this new environment variable value.
16+
17+
After a while I noticed that there was a yellow warning sign next to the terminal process.
18+
When hovering over it it asks you to relaunch the terminal because the environment changed.
19+
It took me a long time to figure this out in the first place.
20+
It's not something I expected and not very intuitive.
21+
22+
I had looked in the past in the settings where this is coming from and how this can be disabled and could not find anything.
23+
Today I finally figured it out, after running into this issue *again* and wasting time until I realized why something did not work.
24+
25+
The popup shown when hovering over the allows you to "Show Environment Contributions".
26+
The [Python VSCode extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) contributed the variables and causes this behaviour.
27+
In *Settings > Extensions > Python* there is an entry called "Env File" that contains `${workspaceFolder}/.env`.
28+
Remove the value and relaunch the terminal.
29+
30+
Now changes to your `.env` file won't affect your terminal's environment anymore.

0 commit comments

Comments
 (0)