Solved 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 -
@Giakara said in 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
What exactly have you tried?
-
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 -
You need to give the correct path. I doubt that your program is in the same directory as your current app.
-
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
-
@Giakara please provide a minimal and reproducible example.
-
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. -
@JonB OR
self.p.start(sys.executable, ['/full/path/to/main.py'])
-
@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!
-
@Giakara
Out of interest, what does yourprint(sys.executable)
output? -
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. -
@JonB venv\Scripts\python.exe full path to python.exe
-
@Giakara
Wow! So you are on Windows and were trying to runpython3
as the executable! OK :)