Troubleshooting .env File

Hello Everyone,

I’m currently working with some credentials in my Python project and’d like to utilize a .env file to manage them securely.

Here’s a snippet of my code:
import os
PROJECT_ID = os.environ.get(“PROJECT_ID”)

However, I’m facing an issue where PROJECT_ID returns None. I’ve placed the .env file in the same directory as the file, but it doesn’t seem to work.

Could anyone guide me on the correct path to place the .env file?

Additionally, I’m attempting to use both python-dotenv and python-decouple . However, when I install python-dotenv using pip3 install python-dotenv and add from dotenv import load_dotenv, I encounter the error: ModuleNotFoundError: No module named 'dotenv'. Similarly, after installing python-decouple with pip3 install python-decouple and adding from decouple import config, I faced the error: ModuleNotFoundError: No module named 'decouple'.

Can anyone assist with how to properly use a .env file, whether through os.environ, python-dotenv, or python-decouple?

Your help and suggestions are greatly appreciated.

Thank you!
Anisha Jain