0

When I run the below code, the child scripts no longer execute. How can I make the master script and other child scripts work once they turn into .exe?

I have created a masterscript using PysimpleGUI and it works when I keep everything in script form using subprocess

This Master script works while as a .py form but not when I turn into a .exe using pyinstaller

import PySimpleGUI as sg
import subprocess
def A():
    path = 'C:/python_work/'
    os.chdir(path)
    subprocess.call(['python', 'scripta.py'])

    sg.PopupOK('All Done!')
def B():
    path = 'C:/python_work/'
    os.chdir(path)
    subprocess.call(['python', 'scriptb.py'])
    sg.PopupOK('Done')
func_dict = {'A':1, 'B':2}    

I've tried an import scriptA method but everytime it just runs the script instead of waiting for the GUI prompt.

As a note i've tried going into the child scripts and utilizing:

    print('hello world')
if __name__ == "__main__":  

This method hasn't worked, the scripts are 300 lines and don't like being put into def

Pat
  • 41
  • 6
  • 1
    Seems like subprocess is the key here. Did you google pyinstaller and subprocess? When I did, I got this as the first link that seems to explain a bit of why you're having problems. Care must be taken https://github.com/pyinstaller/pyinstaller/wiki/Recipe-subprocess – Mike from PSG Sep 11 '19 at 22:21
  • Thanks! This actually didn't solve the issue but has started to point me in the right direction. It seems that any OS path wasn't working at all which is probably why scripts weren't working. In the end we are keeping them in Script form and loading them automatically with a .Bat file – Pat Sep 13 '19 at 13:55
  • Oh, paths! Didn't think about that. BTW, I always preface my paths with r'' just in case. path = r'c:/python/' Then you don't have to worry about slashes in either direction. Glad you're at least in a positive direction! – Mike from PSG Sep 13 '19 at 20:50

1 Answers1

0

It appears there is an issue with the internal permissions and OS file path working after a pyinstaller to .exe file.

We solved this by launching the scripts automatically from a .bat file keyed off by an internal tool. This required all the imports to be saved in a zip folder with the install.

Not an ideal solution but it does work.

Pat
  • 41
  • 6
  • 1
    What happens if in your example you don't try to use os.chdir but instead pass in the full path to your subprocess? I never use relative paths out of habit. Instead of passing in just 'scripta.py' what if you include the entire path to it? – Mike from PSG Sep 13 '19 at 22:39