Use environment variables defined in `.env` file when running code in a terminal
See original GitHub issue@brettcannon
I’ve been using PYTHONPATH
variable in .env
for debugging using experimental debugger (without having to pip install PTVSD).
However running in terminal doesn’t inherit these variables, I’ve had to export them manually.
What do you think about this feature?
Technical solution outlined in #4310 Need spec to provide UX (prompting users to load env, etc)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:116
- Comments:52 (7 by maintainers)
Top Results From Across the Web
How To Use Environment Files with env-cmd | DigitalOcean
Learn how to add handle environment variables with the env-cmd package.
Read more >Working with Environment Variables in Node.js - Twilio
An alternative way to load . This command-line tool will load a . env file, initialize the values using dotenv, and then execute...
Read more >How to use a .env file to load environment variables in a dev ...
Loading environment variables using a . env file when working with Remote - Containers or GitHub Codespaces. Check out the docs for more...
Read more >Use environment variables in Terminal on Mac - Apple Support
You can create environment variables and use them to control the behavior of a command without modifying the command itself. For example, you...
Read more >What is .env ? How to Set up and run a .env file in Node?
Environment variables are already included in the Node.js ecosystem, which gives them a significant benefit over alternative configuration ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would like to ask for some clarification on this issue, please. As of 2he VS Code documentation on Python Environments as of 8/2/20 says:
I interpret this to mean that when VS Code finds a
.env
in the root of the workspace it will read the file and set any environment variables found in it in the current shell before the code is executed.I have a
.env
file in the root of my workspace as follows:I also have a file,
envtest.py
, in the root of the workspace that looks like this:When I run this code in the integrated terminal (either Powershell or WSL) or if I remote into WSL I get output like the following:
😖
When I run this code in the debugger I get the expected output; i.e. the environment variables are set and their values are printed to the screen.
😕
This behavior is maddeningly inconsistent and seemingly contradicts the documentation. 😠 Is there any plan to standardize the behavior and/or correct the documentation?
The whole
"python.envFile"
feature needs much better documentation/support (#544)…I don’t know if or how it works, I don’t know if I can or how to refer to other variables inside
.env
(e.g. DoesPYTHONPATH=${PYTHONPATH}:${workspaceFolder}/utility
work?), etc.From an hour of trying to use it, it appears nobody on the internet knows what’s going on. It’s either people who can’t get it to work either or people saying it does work but not giving realistic examples… grrr!!!