Skip to content

environment variable recording issue

os.getenv("OPENAI_API_KEY") returns None I check environment variable OPENAI_API_KEY exist but i use set command because export command generate an error What the issue of it ? I check again and the set command put variable in users variables not in system. then i try manually put by power shell use follow command
[Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "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", "Machine") And now I get the result thats variable exist in system variables But still returns None in os.getenv() AND solving by next code os.environ["OPENAI_API_KEY"] = "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" api_key = os.environ.get("OPENAI_API_KEY")