title: Using Subprocess to Check sudo-apt install Return Value?
body: <p>I'm currently writing a shell script using Python 2.7. To install virtual-env I am using the following:</p>
  <pre><code>def setup_virtal_env(package): 
      try: 
          subprocess.call('apt-get update', shell=True)
          command = subprocess.call(&quot;apt-get install python-&quot; + package, shell=True)
          proc = subprocess.check_call(str(command), stdin=PIPE, stderr=subprocess.STDOUT)
          stdoutdata, stderrdata = proc.communicate(),
          assert proc.returncode == 0, 'Installed failed...'
          print proc.returncode
      except subprocess.CalledProcessError: 
          print &gt;&gt; sys.stderr, &quot;Execution failed&quot;, 'OSError,', 'trying pip...'
          'Installed virtualenv with pip...' if install_pip(package) else 'Pip failed...'
  </code></pre>
  <p>My question is how can I use <code>subprocess.check_call</code> or <code>subprocess.check_output</code> to check if the user already has <code>virtualenv</code> installed or if it installed correctly. As of right now when I call <code>.check_call()</code> it returns:</p>
  <pre><code>File &quot;install_.py&quot;, line 121, in setup_virtal_env
  proc = subprocess.check_call(str(command), stdin=PIPE, stderr=subprocess.STDOUT)
  File &quot;/usr/lib/python2.7/subprocess.py&quot;, line 535, in check_call
  retcode = call(*popenargs, **kwargs)
  File &quot;/usr/lib/python2.7/subprocess.py&quot;, line 522, in call
  return Popen(*popenargs, **kwargs).wait()
  File &quot;/usr/lib/python2.7/subprocess.py&quot;, line 710, in __init__
  errread, errwrite)
  File &quot;/usr/lib/python2.7/subprocess.py&quot;, line 1327, in _execute_child
  raise child_exception
  OSError: [Errno 2] No such file or directory
  </code></pre>
  <p>Is there a way I can use <code>subprocess</code> to check if <code>virtualenv</code> is installed correctly?</p>