-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use environment variables defined in .env
file when running code in a terminal
#944
Comments
The whole I don't know if or how it works, I don't know if I can or how to refer to other variables inside 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!!! |
How hard is it to launch with these environment variables set? Does the VS Code API make it easy? If it does then doing it through |
@dakotahawkins and yes, more docs would be good, hence why #544 exists. 😄 If you're up for helping us get that issue closed then it would be appreciated! Else we do plan on getting around to it. |
@dakotahawkins
|
@brettcannon I'd be happy to help out, provided I can figure out how it works or how it's intended to work for more complicated values than Another issue I had is that "run in terminal" didn't work after setting my terminal to bash (git bash, still on windows) because it sent it windows path separators. It occurs to me that these differences might apply to environment variables as well (e.g. separating lists with In the interim I just went back to cmd.exe. That's probably a separate feature request but I thought I'd mention in here since it could be relevant to processing |
@dakotahawkins you're right that the |
At any rate, and more on-topic, one of the things I tried was running a temp I guess my secondary complaint, besides not knowing how to use it in the first place, is that it seems like there is no way to tell what you're actually getting out of Transparently setting them when you run in the vscode terminal would have allowed me to do that, but on the other hand I could definitely see it being a big problem for python to work fine from vscode but not anywhere else (because only vscode would be using the I don't know what the "most native" python solution to that would be, but whatever it is should be (imo) as helpful as possible to people who aren't going to run it from inside of vscode. As I mentioned in #955, my use-case is that I already don't use vscode to run my code and so while that will work I want to be able to get vscode to find all the things my running code would find (without setting absolute paths, because other developers will work on this). The problematic use-case would be the opposite -- some project that starts in vscode becoming dependant on it because of features like this. |
Typically people use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
To help manage our issues and to better communicate what the team plans to work on we are closing issues that we don't plan to work on but would accept a pull request from a volunteer for. To be clear, closing this issue does not mean we won't consider a pull request for this enhancement as outlined in our contributing guide, just that the development team has no plans to work on it themselves. |
Apparently PyCharm supports this so might need to have a chat with @qubitron about this. |
A (perhaps not so awesome) workaround is to not use bash and instead use the cross-platform PowerShell as the default terminal for VSCode for Linux/MacOS, then set up your PowerShell profile to load the environment and activate the virtual environment. Now, "Run Python File" and debugging will all load the proper environment. If you have certain tasks in The workaroundInstall PowerShellInstall PowerShell in your distro by adding the Linux Software Repository for Microsoft Products and running Update VSCode workspace settingsThen, e.g. for Linux in your workspace "terminal.integrated.defaultProfile.linux": "pwsh", Install
|
Any updates on this? The documentation is either misleading or this is a bug.
If the intended functionality is to have the env vars load only when debugging a file, that's fine by me; only pointing out that there is some confusion in the docs. |
Ideally the functionality would work similar to Pycharm. Where variables are applied per run/debug configuration. |
I've created a terminal launcher that works around this issue. I didn't like the idea of declaring environment variables in multiple places. The implementation was easy, I really don't know why Microsoft didn't support this feature despite it being a trivial behavior. |
#11039 should fix this issue, still keeping this open as it has more upvotes. |
Any updates on this?
But I need to load the # python-dotenv example
import os
from dotenv import load_dotenv
load_dotenv()
print(os.getenv("API_KEY")) If the intended functionality is not to |
@karrtikr any update when this issue might get fixed? |
There's an open PR for it right now, it's actively being worked on 🙂 |
Should be fixed with #11039, but it is currently behind an experiment. Give it a try:
|
…ctivation` experiment (microsoft#21879) For microsoft#944 microsoft#20822 We only apply those env vars to terminal which are not in process env variables, hence remove custom env vars from process variables.
If this graduates from being experimental, docs would need to be updated. |
@starball5 Thanks, I've added it to our existing issue to track this: microsoft/vscode-docs#6590 |
The setting |
That'll be Remote settings instead of User settings for remote scenarios. |
Thank you for fixing this. It's already been mentioned in the above comments, but for those who are trying to implement this and have not messed with experimental settings, here's how to add it:
|
@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)
The text was updated successfully, but these errors were encountered: