I have a python script that is compiled into an exe with pyinstaller file.py --onedir
and distributed to different machines.
Now, in my file.py
I have multiple different values that should be configured with a config file depending on what machine it is on, and I am unsure the best way to approach this.
My config.ini
looks like:
[Section1]
key1 = "\path1..."
key2 = "\path2..."
key3 = "\path3..."
In my file.py
I get the values with:
from configparser import ConfigParser
config = ConfigParser()
config.read("config.ini")
val1 = config.get('Section1', 'key1')
val2 = config.get('Section1', 'key2')
val3 = config.get('Section1', 'key3')
...
# the rest of my code
My thought process was to have the config file in one location instead of distributing it with the exe to the different machines. However, the issue with that is if the exe’s are executed at the same time and all pulling from the same file, then the config values they get would not be correct.
My next thought was to distribute the config with the exe, while allowing the config to be editable. I can’t compile the config into the exe because it will not be editable. But The issue I run into with this is that the exe’s are all the same. So in my script, I am unsure how to locate each config file since they would not have the same path.
What would be a good approach to use a configuration file with the exe if the exe needs to be distributed to multiple machines, which will require different configuration values?
Everything I have found on SO has not helped my case so far, so any suggestions would help