pyinstaller subprocess.check_output错误

时间:2019-02-04 09:01:09

标签: python

我已将我的应用与pyinstaller捆绑为2个*.exe

gui_app.exe (onefile)
config.ini
\libs (onedir)
     winservice.exe
     + all DLLs and libs

当我使用命令winservice.exe install手动安装服务时,一切都很好,但是当我使用来自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)

我收到此错误:

 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'

为什么要在config.ini中寻找AppData?当我显示当前工作目录msg.showinfo("", os.getcwd())时,它将显示包含应用程序文件和目录的当前目录。我也在config.ini代码中定义了winservice的路径,也使用gui_app对其进行了编辑。

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)

configparse中(无论如何它被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"))

1 个答案:

答案 0 :(得分:0)

问题出在configparser中。我已将功能添加到独立的gui_app中,以排除从主代码交叉导入的变量。