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 is not reloaded/interpolated #9480

Closed
1 of 2 tasks
janrito opened this issue Mar 24, 2022 · 9 comments
Closed
1 of 2 tasks

.env file is not reloaded/interpolated #9480

janrito opened this issue Mar 24, 2022 · 9 comments
Assignees
Labels
triage-needed Issue needs to be triaged

Comments

@janrito
Copy link

janrito commented Mar 24, 2022

Applies To

  • Notebooks (.ipynb files)
  • Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

I've been trying to add some additional search paths to PYTHONPATH, so I created an env file

PYTHONPATH='lib:crawler:api:${env:PYTHONPATH}'

There are a few problems:

  1. The variable was never interpolated, e.g. the output of sys.path is:
['/Users/janrito/path/to/project',
 '/Users/janrito/path/to/project/notebooks',
 '/Users/janrito/path/to/project/notebooks/lib',
 '/Users/janrito/path/to/project/notebooks/crawler',
 '/Users/janrito/path/to/project/notebooks/api',
 '/Users/janrito/path/to/project/notebooks/${env',
 '/Users/janrito/path/to/project/notebooks/PYTHONPATH}',
 '/opt/homebrew/Caskroom/miniforge/base/envs/project-env/lib/python39.zip',
 '/opt/homebrew/Caskroom/miniforge/base/envs/project-env/lib/python3.9',
...
]
  1. I cannot reload the environment variables. I've tried restarting the kernel, the language server, vscode itself - with no success. I deleted the .env file sys.path remains the same

  2. The path relative root is wrong:

In .vscode/settings.json I have set:

"jupyter.notebookFileRoot": "${workspaceFolder}",

The additional search paths should have been added relative to the project root, not relative to the notebooks directory.

VS Code Version

Version: 1.66.0-insider

Jupyter Extension Version

v2022.3.1000851004

Jupyter logs

No response

Coding Language and Runtime Version

Python v3.9.10 from miniconda

Language Extension Version (if applicable)

v2022.3.10831003

Anaconda Version (if applicable)

mamba 0.22.1 conda 4.12.0

Running Jupyter locally or remotely?

Local

@janrito janrito added bug Issue identified by VS Code Team member as probable bug needs-triage labels Mar 24, 2022
@DonJayamanne
Copy link
Contributor

Thanks for filing this issue, unfortunately we don't support this feature in the extension.
Will discuss with the team about this issue.

@DonJayamanne DonJayamanne assigned DonJayamanne and unassigned amunger Mar 25, 2022
@DonJayamanne DonJayamanne added enhancement and removed bug Issue identified by VS Code Team member as probable bug labels Mar 25, 2022
@janrito
Copy link
Author

janrito commented Mar 25, 2022

Thanks for looking into this @DonJayamanne!

I guess there are two important things here:

  1. If .env files are not supported by the extension python environment should not be polluted by wrongly reading them. And if it has read them, how do we reload the environment so that it removes any trace of it.
  2. Is there a supported way to injecting environment variables to the jupyter process?

@DonJayamanne
Copy link
Contributor

DonJayamanne commented Mar 25, 2022

to be clear, .env files area supported, but not replacing tokens such as ${env:PYTHONPATH} with something else.
Jupiter extension is not specific to just python, apples to R, julia, etc, hence not sure about the tokens used in env files, i think this is specific to python.

once again, we'll focus this within the team and we'll update this issue accordingly

@rchiodo
Copy link
Contributor

rchiodo commented Mar 28, 2022

Thanks for the issue, but we're not going to pursue this at this time.

@rchiodo rchiodo closed this as completed Mar 28, 2022
@janrito
Copy link
Author

janrito commented Mar 29, 2022

Can you point me on the direction of reloading the .env file?
At the moment, the only thing that worked is nuking the vscode installation and starting from scratch

@DonJayamanne
Copy link
Contributor

Can you point me on the direction of reloading the .env file?

Sorry, but I don't quite understand the question here.

@janrito
Copy link
Author

janrito commented Mar 29, 2022

If an .env file is present, it will load it the first time (I understand that it won't interpolate values). But currently, there is no way of reloading it.

I've tried,
1 restarting the kernel,
2. reloading vscode
3. changing the .env file
4. deleting the .env file
5. recreating the virtual environment

None of these seem to do anything, the original variables loaded the first time will be the ones that the notebook sees.

@DonJayamanne
Copy link
Contributor

@janrito Please could you create a new issue for what you are describing.
It shoudl work, looks like there's some bug somewhere. When filing the issue, please do fill in the issue template and provide the output from Jupyter output logs (after you have updated the .env file and restarted the kernel)

@subercui
Copy link

Any solution to this? I met the same issue/bug.
It never updates the env variable even after restarting everything.
Vscode 1.66.2, vscode-jupyter v2022.3.1000901801

@greazer greazer added triage-needed Issue needs to be triaged and removed needs-triage labels May 16, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
triage-needed Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

6 participants