2

I'm new to python and pyinstaller, I'm working on building a small app where my main.py has two push buttons that call scripts when clicked, here is my main.py file:

import subprocess, button1script, button2script

qtCreatorFile = "notepad_grid.ui" 

Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)

class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        QtWidgets.QMainWindow.__init__(self)
        Ui_MainWindow.__init__(self)
        self.setupUi(self)
        self.button1.clicked.connect(lambda:self.run('button1script.py'))
        self.button2.clicked.connect(lambda:self.run('button2script.py'))

    def run(self, path):
        subprocess.call(['python',path])


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = MyApp()
    window.show()
    sys.exit(app.exec_())

This app works fine before packaging with pyinstaller, I can run main.py and clicking on the buttons calls the corresponding script and open new windows. After I run pyinstaller with command "pyinstaller --onedir "main.py"" the main exe file works but when I click on the buttons I get an error message:

Traceback (most recent call last):
  File "MainApp.py", line 14, in <lambda>
  File "MainApp.py", line 18, in run
  File "subprocess.py", line 557, in call
  File "subprocess.py", line 947, in __init__
  File "subprocess.py", line 1224, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

All the files are on the same folder when I run pyinstaller. Can anyone help figuring out what the issue is? Thanks

Anis
  • 21
  • 3
  • 1
    I can see two possible problems. First, when you run the frozen exe the pyinstaller runs in [a different folder](https://pythonhosted.org/PyInstaller/advanced-topics.html#the-bootstrap-process-in-detail). [This](http://stackoverflow.com/a/32048136/3837382) could solve the issue. Second, I suspect that if you run the frozen code in a PC without python in the `PATH`, the subprocess call will give you an error. – Repiklis Sep 23 '16 at 10:05

0 Answers0