Run python script in Qt
-
put
python -c 'print "Hello World"'
in p.start@NotYourFan It doesn't work like this. You have to put the command as first parameter to start() and all parameters for the command as parameter list.
-
@NotYourFan It doesn't work like this. You have to put the command as first parameter to start() and all parameters for the command as parameter list.
-
wrote on 4 Jul 2019, 05:37 last edited by NotYourFan 7 Apr 2019, 05:38
-
Hi,
@NotYourFan just in case, did you try to compare the environment variables of your QProcess object and the one you have when running e.g. from a terminal ?
@Gojir4 You are right about that specific overload, but the documentation also states that this overload should be avoided if possible.
-
Hi,
@NotYourFan just in case, did you try to compare the environment variables of your QProcess object and the one you have when running e.g. from a terminal ?
@Gojir4 You are right about that specific overload, but the documentation also states that this overload should be avoided if possible.
-
put
python -c 'print "Hello World"'
in p.startwrote on 4 Jul 2019, 07:34 last edited by@NotYourFan
I am lost as to where you are now.Assuming it's still crashing --- is that right? --- surely you want to break it down to simplify now. Start with:
params << "-V"; p.start("C:\\development\\Python\\Python37\\python.exe", params); p.waitForFinished(-1); QString p_stdout = p.readAll();
What exactly happens?
-
wrote on 4 Jul 2019, 09:10 last edited by
@JonB, i get a error Message: ….
ModuleNotFoundError: No module named 'encodings'
-
@JonB, i get a error Message: ….
ModuleNotFoundError: No module named 'encodings'
wrote on 4 Jul 2019, 09:18 last edited by JonB 7 Apr 2019, 09:19@NotYourFan
OK! So, you can forget about yourcreateJSON.py
script and anything it does.I don't know why you get this when spawning from Qt but not when running your
python.exe
directly from a command prompt. Either it's something to do with it sending output to a pipe you are reading from, or it's to do with your general Python environment being different between the two situations.You want now to Google for
python ModuleNotFoundError: No module named 'encodings'
. There are posts/suggestions. Looks to me like it might be to do with whether you are using a virtual environment or not, but I'm sure one of the hits will sort you out.... -
@NotYourFan
OK! So, you can forget about yourcreateJSON.py
script and anything it does.I don't know why you get this when spawning from Qt but not when running your
python.exe
directly from a command prompt. Either it's something to do with it sending output to a pipe you are reading from, or it's to do with your general Python environment being different between the two situations.You want now to Google for
python ModuleNotFoundError: No module named 'encodings'
. There are posts/suggestions. Looks to me like it might be to do with whether you are using a virtual environment or not, but I'm sure one of the hits will sort you out....@JonB I can imagine that the Environment inside Qt Creator is different (e.g. PATH) and therefore other (incompatible) executables and libraries are found.
@NotYourFan: You should carefully check the Run Environment variables inside Qt Creator, especially PATH. That's all I can say for now.
Regards
-
wrote on 4 Jul 2019, 09:33 last edited by
-
wrote on 4 Jul 2019, 09:40 last edited by
@aha_1980 !!!!!
Thank you :=)That was the Problem.
I use for "Debug" MinGW (MinGW included python2.7 and set a PYTHON variable)
So now i tried like this:QProcess cmd; QProcessEnviroment env = QProcessnviroment::systemEnviroment(); QProcessEnviroment envUpdate; envUpdate.inser("PATH", env.value("PATH")); cmd.setProcessEnviroment(envUpdate) cmd.start("python.exe C:\\Users\\...\\Desktop\\...\\createJSON.py") cmd.waitForFinished();
Now it works :)
Thank you @all for your standby
-
21/31