Pyinstaller subprocess.check_output error

2024/10/8 10:49:43

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_installFile "<frozen importlib._bootstrap>", line 983, in _find_and_loadFile "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 677, in _load_unlockedFile "c:\users\rs_al\dev\pyxlsql\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_moduleexec(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 openfile = 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"))
Answer

Problem was in configparser. I've added function to standalone gui_app to exclude variables cross import from main code.

https://en.xdnf.cn/q/118709.html

Related Q&A

Exception handler to check if inline script for variable worked

I need to add exception handling that considers if line 7 fails because there is no intersection between the query and array brands. Im new to using exception handlers and would appreciate any advice o…

Parameter list with single argument

When testing Python parameter list with a single argument, I found some weird behavior with print.>>> def hi(*x): ... print(x) ... >>> hi() () >>> hi(1,2) (1, 2) >>…

Scatter plot of values in pandas dataframe

I have a pandas dataframe in the following format. I am trying to plot this data based on ClusterAssigned, with probably different colors for 0 and 1. Distance ClusterAssigned23 135 120 …

String Delimiter in Python

I want to do split a string using "},{" as the delimiter. I have tried various things but none of them work.string="2,1,6,4,5,1},{8,1,4,9,6,6,7,0},{6,1,2,3,9},{2,3,5,4,3 "Split it i…

Wrong encoding of email attachment

I have a python 2.7 script running on windows. It logs in gmail, checks for new e-mails and attachments:#!/usr/bin/env python # -*- coding: utf-8 -*-file_types = ["pdf", "doc", &quo…

Blank lines in txt files in Python

I want to write sensor values to a text file with Python. All is working fine but one thing; in the text file, there are blank lines between each value. Its really annoying because I cant put the value…

Python 3 - decode spectroscopy data (Base64, IEEE754)

Im a chemist and working with spectroscopic data that was stored as a list (501 pairs of X,Y data) of Base64-encoded floating point values according to IEEE754.I tried to get an array of X, Y data to w…

Fill new column by following conditions listed in a dictionary [duplicate]

This question already has an answer here:Insert data to new column based on conditions given in dictionary(1 answer)Closed 2 years ago.I have the dictionary specifying the value the row should take if …

Pandas - Splitting dataframe into multiple excel workbooks by column value

Im new to pandas. I have a large excel file, what I’m trying to do is split the data frame after manipulation into multiple excel workbooks. There is more or less 400 vendors and I would like each To …

Create Sections in Python

I am newbie to Python. I have large file with repetitive string through the logsExample:abc def efg gjk abc def efg gjk abc def efg gjk abc def efg gjkExpected Result--------------------Section1-------…