python - compiled calling config file -
i'm compiling python application using pyinstaller.
the structure -
d:\app\myprog.exe d:\app\config\settings.conf
if run myprog.exe --switch value
d:\app
runs fine, if try run anywhere else c:\windows
it's not finding settings.conf
file complaining message:
traceback (most recent call last): file "<string>", line 284, in <module> file "<string>", line 218, in main file "configparser.py", line 330, in configparser.nosectionerror: no section: 'database' myapp returned -1
database
being first line in config file i'm trying reference.
i'm referencing base_dir
app here -
# global path , config info try: base_dir = os.path.dirname(os.path.abspath(__file__)) except nameerror: # main py2exe script, not module base_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
so can config file -
config = rawconfigparser() config.read(os.path.join(base_dir, 'config/settings.conf'))
but guess base_dir
whatever folder i'm running exe (like c:\windows
, not location of exe (which d:\app
)?
as mentioned in pyinstaller documentation (in how one-file program works section) when single executable file (created pyinstaller) executed, happens directory structure of required library modules (python vm, libraries , packages, etc.) extracted single executable temporary directory, , application started there.
this means __file__
in python code not going path single executable file, , that's reason issue.
i'd write app accept path configuration file command line arguments, fall using environment variable if available, , hard coded default value based on platform (as multi platform applications reach configurations).
another approach use one-directory output pyinstaller , include configuration file in same directory. make easier distribute software end users, use tool create single windows installer file directory structure. way you'll distributing windows installer, users can run install application. when app runs, runs directory configuration file resides.
Comments
Post a Comment