1

I’m having trouble getting my Python script to read the environment variables in my virtual environment.

I made a virtual environment in VSCode and created a separate .env file to hold the environment variables.

My .env file:

MSG = “Hello World! I am an environment variable”;

helloworld.py:

import os
msg = os.getenv(“MSG”,”Couldn’t find the environment variable”)
print(msg)

Which prints the default message “Couldn’t find the environment variable”

My file tree looks as such:

——

.venv

helloworld.py

.env

—-

Any help on how to get my script to read the environment variables in .env?

Thanks!

0 Answers0