Ok so based on the comment above, to help future users who might not be aware of this, you cannot set environment variables outside the scope of the current process with Python.
You can make python aware of some variables and change env variables for the scope of a process and its child processes. But you can not set values for env in the system itself or other processes (that are not children of the current process). For example if I set a env variable called HOST_URL
it wont be actually accessible in the system environment.
I found three ways to actually set the variables by:
- Running a bash script to set the env variable values
- Use VSCode
launch.json
for setting the variables either with env
or envFile
- Define them through
Docker
file or docker-compose.yml
if you are containerizing your app
Note:
If there are other options to address this please comment and I ll add them. I want this to be a helpfull post for new developers like myself. Shaming and non-helpful comments never helped anyone or improved anything. This is, or should be, a learning and knowledge exchange platform and it should be open to all programming questions Stack Overflow Isn’t Very Welcoming. It’s Time for That to Change