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.

Load environment variables from .env file and global variables

See original GitHub issue

Refs: #10359

Complexity: 3

Authors: @DonJayamanne

Create Issue

Create Issue


Requirements

  • Install prerelease jupyter extension into VS Code Insiders (desktop)
  • Have a python environment that you can run jupyter from. (https://jupyter.org/install)
  • Be familiar with jupyter notebooks
  • Use Python 3.6 or later (please ensure you aren’t using Python 2, use python --version to check the version)

Test loading variables from .env file

  1. Open a folder in VS Code
  2. Add a file named .env
  3. Add an environment variable to the file
  4. Create an ipynb file in the root directory
  5. Run a cell in the ipynb file to print the value of the above env variable
import os
print(os.getenv(<env variable>))
  1. Verify the right value is printed
  2. Updated the value in the .env file
  3. Restart the kernel and verify the new value is printed.

Test loading variables from global env variables

  1. Exit VS Code completely
  2. Create a global environment variable (on windows use env varaibles editor and unix update ~/.bashrc or the like)
  3. Open a folder in VS Code
  4. Create an ipynb file in the root directory
  5. Run a cell in the ipynb file to print the value of the above env variable
import os
print(os.getenv(<env variable>))
  1. Verify the right value is printed
  2. Updated the environment variable
  3. Exit vscode completely and reload VS Code
  4. verify the new value is printed when running a cell again

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rchiodocommented, Jul 26, 2022

Entered #10940

0reactions
DonJayamannecommented, Sep 27, 2022

@jtele2 please file a separate issue with the results and steps required to repro the issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using .env Files for Environment Variables in Python ...
Using a .env file will enable you to use environment variables for local development without polluting the global environment namespace.
Read more >
Working with Environment Variables in Node.js - Twilio
Explicity loading varibles from .env files. You can access environment variables in Node.js right out of the box. When your Node.js process ...
Read more >
Environment variables in Compose | Docker Documentation
You can set default values for environment variables using a .env file, which Compose automatically looks for in project directory (parent folder of...
Read more >
Environment Variables: What They Are and How To Use Them
Environment variables help you isolate critical application configuration data using env files or remote variable stores.
Read more >
Basic Features: Environment Variables - Next.js
In general only one .env.local file is needed. However, sometimes you might want to add some defaults for the development ( next dev...
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