Module subprocess has no attribute 'STARTF_USESHOWWINDOW'

前端 未结 4 2044
眼角桃花
眼角桃花 2020-12-19 01:27

Hi Stack Overflow users,

I\'ve encountered a frustrating problem, can\'t find the answer to it.

Yesterday I was trying to find a way to HIDE a subprocess.Pop

相关标签:
4条回答
  • 2020-12-19 02:02

    python 3.1.3 > and 2.7

    import subprocess
    import sys
    
    params = dict()
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    params['startupinfo'] = startupinfo
    
    p = subprocess.Popen("cmd.exe", **params)
    
    0 讨论(0)
  • 2020-12-19 02:14

    I had misread the question, sorry. You might have something shadowing either the subprocess or _subprocess module. If it's an install glitch, try removing and reinstalling Python 3.

    0 讨论(0)
  • 2020-12-19 02:20

    You can recreate or check the described problem in your Python installation:

    import subprocess
    subprocess.STARTF_USESHOWWINDOW
    

    If the problem persists you should receive error message ending with line like this:

    AttributeError: 'module' object has no attribute 'STARTF_USESHOWWINDOW'
    

    Possible solution of the problem is to import in your code old library by this way:

    import subprocess
    import _subprocess
    

    And later use it only for these two problematic properties:

    # do not show window
    info = subprocess.STARTUPINFO()
    info.dwFlags = _subprocess.STARTF_USESHOWWINDOW
    info.wShowWindow = _subprocess.SW_HIDE
    

    That's it. Simple and functional - without any uninstall/install of Python or reverting back to the old builds.

    0 讨论(0)
  • 2020-12-19 02:22

    Either the reinstall went wrong or you created a module called subprocess.py and forgot it. :)

    Try the following:

    import subprocess
    print(subprocess.__file__)
    

    That should give you the path to your current Windows installations subprocess module, ie.

    C:\Python31\Lib\subprocess.pyc
    

    If it instead says

    C:\PYthon31\subprocess.py
    

    It's importing a module you created. (You may want to consider not putting your Python files in the Python directory, as in your example above. Having a separate directory for each project is a better idea, and might mean you don't have to install Python so often. ;) )

    0 讨论(0)
提交回复
热议问题