0

I have created a workspace on my local machine to connect to Linux server. I connect to this server in VS Code using SSH extension as outlined in these docs. https://code.visualstudio.com/docs/remote/ssh#_managing-extensions.

When I run the .py application in my Local Workspace I get the error UndefinedValueError: CREDENTIALS not found. Declare it as envvar or define a default value.

The .py application is in the same directory as the .env file which houses the CREDENTIALS variable on the Linux server and when run on the Linux server works fine..

How do I tell vscode on my local machine to access the .env file when Im running the .py application locally?

from decouple import config

credentials = config('CREDENTIALS')

Only started working in this type of coding environment today so apologies in advance if I have missed something very simple...

1 Answer 1

1

Use the python-dotenv library, nice and easy. Install via
pip install python-dotenv

Then in your file call

from dotenv import load_dotenv Then just call load_dotenv()
And all your env variables declared in the file will be put into the environment table. As long as that config function is grabbing env variables it should work. If it doesn't, you could use

Import os
from dotenv import load_dotenv
load_dotenv()
EnvVar = os.getenv('CONFIG')
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your help using the above both ways I get OSError: Starting path not found.. Any ideas? Im assuming it cant find the .env
Got it , I specified the path to the .env from the linux server in load_dotenv that worked.. Thanks allot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.