.pyw and pythonw does not run under Windows 7

后端 未结 7 1403
猫巷女王i
猫巷女王i 2020-12-13 19:46

Running a simple .py or .pyw python file causes python.exe to show up under Task Manager.

python myApp.py
python myApp.pyw

How

7条回答
  •  春和景丽
    2020-12-13 20:04

    I faced the same problem on a script of my own and found that when adding the output from Ross' answer the script would actually run.

    It appears that for some reason that redirecting output fixes the problem. Since I'm not interested in writing the output to disk I've instead written it to /dev/null (or the platform equivalent) with:

    if ( sys.platform == 'win32' and sys.executable.split( '\\' )[-1] == 'pythonw.exe'):
        sys.stdout = open(os.devnull, 'w')
        sys.stderr = open(os.devnull, 'w')
    

    The if statement ensures it only happens when the script is launched from pythonw.exe. I'm not sure if it is related but it was important to do this before other imports (including e.g. import logging).

提交回复
热议问题