I've bundled my app with pyinstaller
to 2 *.exe
gui_app.exe (onefile)
config.ini
\libs (onedir)
winservice.exe
+ all DLLs and libs
When I manually install service with command winservice.exe install
everything is fine, but when I use command from GUI:
def svc_install(self):
try:
svc_inst = sb.check_output([os.getcwd()+"\libs\winservice.exe", "--startup=auto", "install"])
except WinError as e:
msg.showerror(e)
I get this error:
File "tkinter\__init__.py", line 1705, in __call__
File "gui\pagethree.py", line 24, in <lambda>
File "gui\pagethree.py", line 35, in svc_install
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "c:\users\rs_al\dev\pyxlsql\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "utils\configparse.py", line 20, in <module>
File "C:\Users\rs_al\AppData\Local\Programs\Python\Python37-32\lib\codecs.py", line 898, in open
file = builtins.open(filename, mode, buffering)
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\rs_al\\AppData\\Local\\Temp\\config.ini'
Why it's looking for config.ini
in AppData
? When I display current working directory msg.showinfo("", os.getcwd())
instead , it shows current directory with app files and dirs. I define path to config.ini
in winservice
code, also and I use gui_app
to edit it.
self.filename = 'config.ini'
with codecs.open(self.filename, "r", encoding="utf-8-sig") as self.config_file:
self.config_ini.insert(tk.INSERT, self.config_file.read())
self.config_ini.bind()
def save_to_file(self):
with open (self.filename, "w", encoding="utf-8-sig") as self.config_file:
data = self.config_ini.get('0.0', tk.END)
self.config_file.write(data)
In configparse
(anyway it's overridden by Pyinstaller
)
default_path = str(Path(__file__).parents[2])
default_config_file = str(Path(default_path+"\config.ini"))
config.read_file(codecs.open(default_config_file, encoding="utf-8-sig"))