Popen error: [Errno 2] No such file or directory

user1012451 picture user1012451 · Mar 30, 2012 · Viewed 69.5k times · Source

I have some custom commands.

# works 
subprocess.Popen(['python'], stdout=subprocess.PIPE)

But if I have my own system commands like deactivate, I get that error

Traceback (most recent call last):
  File "runner2.py", line 21, in <module>
    main() 
  File "runner2.py", line 18, in main
    subprocess.Popen(['deactivate',], stdout=subprocess.PIPE)
  File "/usr/lib/python2.6/subprocess.py", line 633, in __init__
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Let alone I need to execute this under my sandbox virtualenv.

Answer

Anthony Kong picture Anthony Kong · Mar 30, 2012

Try add an extra parameter 'shell=True' to the Popen call.