QProcess successfully launched .py file but can only do few python functions, but if i run .py in pycharm or cmd,everything works well

Issue

This Content is from Stack Overflow. Question asked by Yuesheng Ke

i have a .py file like this:

print("yt_train_log: executing AUO.py")
work_dir = os.path.abspath(os.path.dirname(__file__))
configPath = work_dir + "/train.ini"
config = configparser.ConfigParser()
config.read(configPath)
print("yt_train_log: configPath: {}".format(configPath))
savedStdout = sys.stdout  
sys.stdout = open('out.txt', 'w+') 
sys.stdout = savedStdout 

this python file can well work in pycharm 、 cmd or notebook,but when i use QProcess to excute this .py, it failed. After i delete the last 3 lines from the .py file, it can work well in QProcess. i tryed give admin rights to the .py file and .exe and retry in QProcess, it still failed.



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?