Skip to content
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

.env file not working on run current file action #11174

Closed
fmanno opened this issue Apr 15, 2020 · 4 comments
Closed

.env file not working on run current file action #11174

fmanno opened this issue Apr 15, 2020 · 4 comments
Assignees
Labels
area-terminal feature-request Request for new features or functionality

Comments

@fmanno
Copy link

fmanno commented Apr 15, 2020

Environment data

  • VS Code version: 1.44.1
  • Extension version (available under the Extensions sidebar): 2020.3.7.659
  • OS and version: macOS Catalina 10.15.3
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.7 64 bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): none
  • Relevant/affected Python packages and their versions: n/a
  • Relevant/affected Python-related VS Code extensions and their versions: n/a
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): jedi == False
  • Value of the python.languageServer setting: Microsoft

Expected behaviour

When clicking the green "Play" button on the top right of the editor window I expect the current python file to be executed and the .env file in the workspace to be loaded adding the environment variables in that file to the environment where python executes the file.

Actual behaviour

.env file doesn't seem to be loaded because the expected environment variables are not available in the python script

Steps to reproduce:

  1. Create a folder
  2. Open the folder in VScode
  3. Create a .env file with the contents:
VARIABLE=testing
  1. Create a test.py file with the contents:
import os
print(os.environ['VARIABLE'])
  1. Click the green "Play" button on the top right corner of the editor window
/Volumes/git/env_bug 
02:29 $ /usr/local/bin/python3 /Volumes/git/env_bug/test.py
Traceback (most recent call last):
  File "/Volumes/git/env_bug/test.py", line 2, in <module>
    print(os.environ['VARIABLE'])
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 681, in __getitem__
    raise KeyError(key) from None
KeyError: 'VARIABLE'

Output from Console under the Developer Tools panel:

[Extension Host] Info Python Extension: 2020-04-15 08:48:39: Cached data exists getEnvironmentVariables, /Volumes/git/env_bug
console.ts:137 [Extension Host] Info Python Extension: 2020-04-15 08:48:39: Cached data exists getEnvironmentVariables, extension-output-#4
console.ts:137 [Extension Host] Info Python Extension: 2020-04-15 08:48:51: Cached data exists getEnvironmentVariables, /Volumes/git/env_bug
console.ts:137 [Extension Host] Info Python Extension: 2020-04-15 08:48:54: Cached data exists getEnvironmentVariables, extension-output-#4
console.ts:137 [Extension Host] Info Python Extension: 2020-04-15 08:49:04: Cached data exists getEnvironmentVariables, /Volumes/git/env_bug
console.ts:137 [Extension Host] Info Python Extension: 2020-04-15 08:49:04: Cached data exists getEnvironmentVariables, extension-output-#5
console.ts:137 [Extension Host] Info Python Extension: 2020-04-15 08:49:06: Cached data exists getEnvironmentVariables, /Volumes/git/env_bug
console.ts:137 [Extension Host] Info Python Extension: 2020-04-15 08:49:06: Cached data exists getEnvironmentVariables, extension-output-#9
console.ts:137 [Extension Host] Info Python Extension: 2020-04-15 08:49:16: Cached data exists getEnvironmentVariables, /Volumes/git/env_bug
console.ts:137 [Extension Host] Info Python Extension: 2020-04-15 08:49:20: Cached data exists getEnvironmentVariables, extension-output-#9

If instead I run the same file with the debugger I get the expected result

  1. Run and debug
  2. Current file
/Volumes/git/env_bug 
02:29 $  cd /Volumes/git/env_bug ; env VARIABLE=testing PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /usr/local/bin/python3 /Users/fmanno/.vscode/extensions/ms-python.python-2020.3.71659/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 53281 /Volumes/git/env_bug/test.py 
testing

I have already read all the discussion on #944 and I don't think it's the same. I observe the same as #9358 which I think was closed down prematurely.

@fmanno fmanno added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Apr 15, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Apr 15, 2020
@kimadeline kimadeline added triage-needed Needs assignment to the proper sub-team and removed triage labels Apr 24, 2020
@karthiknadig karthiknadig self-assigned this Apr 27, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Apr 28, 2020
@karthiknadig
Copy link
Member

@fmanno This is not currently supported, switching this to an enhancement.

@karthiknadig karthiknadig added needs decision feature-request Request for new features or functionality area-terminal and removed triage bug Issue identified by VS Code Team member as probable bug labels Apr 29, 2020
@karthiknadig
Copy link
Member

We have marked this issue as "needs decision" to make sure we have a conversation about your idea. We plan to leave this feature request open for at least a month to see how many 👍 votes the opening comment gets to help us make our decision.

@fmanno
Copy link
Author

fmanno commented May 2, 2020

@karthiknadig Thanks for considering this. I think it should behave this way otherwise it's inconsistent with when the debugger is run and could be confusing.
But up to you of course.

@DonJayamanne
Copy link

Closing as a dup of #944

@ghost ghost removed the needs decision label May 3, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-terminal feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants