1

I have an existing Python 3.7 project. When adding a new variable to the .env, it is not loading.

Here is an example of my .env file.

# Existing
DB_HOST=localhost
DB_PORT=3307

# New variable
API_BASE_URL=https://testing.mysite.com.au/api/v1/
# Load api settings
api_base_url = os.getenv('API_BASE_URL') 

The database variables are working fine however, api_base_url returns None.

I don't believe it is a path/load_dotenv issue, as the existing variables are loading correctly.

Do I need to refresh/reload the .env file?

2 Answers 2

1

What environment management system are you using? I think the .env file is a pipenv thing, if so the .env file is only sourced when you call pipenv run ... or pipenv shell. So if you're working in a python you need exit the shell or run.

If you're on a linux machine you can also just source .env to assign the environment variables within the shell.

Sign up to request clarification or add additional context in comments.

1 Comment

I am running in PyCharm using the conda environment and interactive terminal
0

If you use any IDE like visual studio code / Pycharm or similiar you have probably to reload it after changing .env

Not knowing your exact environment and not knowing whether you use autoenv or any other tool it might also be a good choice to explicitly source .env as @it's-yer-boy-chet suggested.

If you're using autoenv, you just had to type cd . and it shoud prompt you whether you want tou source the modified version of .env

Comments

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.