question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.env file is not reloaded/interpolated

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
DonJayamannecommented, 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

0reactions
subercuicommented, Apr 25, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interpolate Environment Variables using Config::Any and the ...
As I understand it, -InterPolateEnv => 1 by itself does not trigger the loading of that module. It is an option which that...
Read more >
Configuration | Prefect Docs
Prefect's settings are stored in a configuration file called config.toml . In general, you should not edit this file directly to modify Prefect's...
Read more >
Property Interpolation — GeoServer 2.23.x User Manual
GeoServer app-schema supports the interpolation of properties (the Java equivalent of environment variables) into app-schema mapping files.
Read more >
python-dotenv - PyPI
Read key-value pairs from a .env file and set them as environment variables. ... Python-dotenv can interpolate variables using POSIX variable expansion.
Read more >
Environment variables in Compose | Docker Documentation
The .env file feature only works when you use the docker-compose up command and does not work with docker stack deploy . Both...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found