Good afternoon all.

I hope that you are well.

I have a Python script that I would like to share with others, however it 
relies on the executable file being able to read a value from a .env file 
stored within the same location as where the executable is being ran from. 
I am running Mac OSX.

Here is some example code :-
import os from dotenv
import load_dotenv

load_dotenv() 

test_environment_variable = os.environ.get("TEST_ENVIRONMENT_VARIABLE") 
print(test_environment_variable) 


The aim is to convert my script into a command executable file and then for 
it to be able to read from an editable .env file within the same directory 
as the executable file. If the .env file is edited and saved, the next time 
the executable is ran, the output will be the contents of the newly saved 
.env file.

I have converted my script to an executable using the following command :-
pyinstaller --onefile main.py 

This results in a dist folder being created with the executable file in 
there. If I place the .env file in the same directory as the executable 
file, then the output of the exe returns "None" whereas I would expect it 
to return "This is a new test environment variable" as per my .env file 
contents :-
TEST_ENVIRONMENT_VARIABLE = "This is a new test environment variable"

I can only assume that when the command application / executable file 
cannot find the .env path that is within the same directory as it and that 
this issue is due to the a problem with absolute vs relative paths. Do I 
need to run pyinstaller with different switches in order to be able to make 
the executable "aware" of the path to look at for the .env file at any time 
it is loaded (it will always be in the same directory as the executable 
file in my use case)? Alternatively, does my code need to be amended to be 
more definitive about the .env file location?

Any help would be greatly appreciated.

Many thanks James

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyinstaller+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyinstaller/50b7392d-cbb1-40bc-b038-5900b3253df3n%40googlegroups.com.

Reply via email to