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
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)
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.
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.
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. ;) )