Run a pyFile(QApplication) from a button of another app
-
Can I Run a pyFile(QApplication) from a button of another app ?? i tried with Qprocess and just call the file but it doesn t open the app
is there any other way or some example -
-
def start_process(self): self.message("Executing process.") self.p = QProcess() self.p.start("python3", ['main.py'])
i didn t find something similar to my problem I m sure i need to put more arguments
main.py is the file with the other executable -
i tried with full path too it doesnt open anything if i just import the file it runs it before i press the button maybe it needs other arguments
-
def start_process(self): self.message("Executing process.") self.p = QProcess() self.p.start("python3", ['main.py'])
i didn t find something similar to my problem I m sure i need to put more arguments
main.py is the file with the other executableself.p.start("python3", ['/full/path/to/main.py'])
is the correct way to run a Python script as a subprocess under Linux, assuming
python3
is on your path (/usr/bin/python3
).Remember that all this does is starts the other process. It doesn't wait for it, it runs in the background. What is it that your Python script does so that you even know whether it has run, or run successfully, or not?
Look at the documentation for
QProcess
. Use the methods and signals to print out the status of the subprocess, capture any error and finished signals, and sometimes you need to capture standard output/error if an error message is sent there. -
self.p.start("python3", ['/full/path/to/main.py'])
is the correct way to run a Python script as a subprocess under Linux, assuming
python3
is on your path (/usr/bin/python3
).Remember that all this does is starts the other process. It doesn't wait for it, it runs in the background. What is it that your Python script does so that you even know whether it has run, or run successfully, or not?
Look at the documentation for
QProcess
. Use the methods and signals to print out the status of the subprocess, capture any error and finished signals, and sometimes you need to capture standard output/error if an error message is sent there. -
@eyllanesc
Yes if you're coming from a Python script, which the OP is, I just meant generically like similar from, say, a C++ program. But indeed. -
@eyllanesc this solved my my problem thank you very much!
-
@eyllanesc this solved my my problem thank you very much!
-
it opens the window that i create on the main.py which is not exactly qt widget it is a wrapinstance of qWidget and i don t know exactly who it works so i do this
@Giakara
Thanks, but that wasn't at all my question. I am interested in knowing what the value of yoursys.executable
Python variable is, since you saidself.p.start(sys.executable, ['/full/path/to/main.py'])
is required to work for you rather than using"python3"
, that's all. -
@Giakara
Thanks, but that wasn't at all my question. I am interested in knowing what the value of yoursys.executable
Python variable is, since you saidself.p.start(sys.executable, ['/full/path/to/main.py'])
is required to work for you rather than using"python3"
, that's all.