How to install subprocess module for python?

The error-text is misleading. Most subprocess-commands expect the shellcmd to be submitted as a list of strings.

In these cases i strongly recommend the usage of the shlex module:

    import shlex
    
    shell_cmd = "test.py"
    
    subprocess_cmd = shlex.split(shell_cmd)
    subprocess.call(subprocess_cmd)

or in this simple case just:

    subprocess.call(["test.py"])

There is no need to install this module in Python 2.7. It is a standard module that is built in.

The documentation shows that it was added to the library for Python version 2.4. It's been with us for a long time now.


The error that you show in your question update is nothing more prosaic than a file not found error. Likely the executable file that you are attempting to call Popen on cannot be found.

That traceback indicates that subprocess is installed and has been imported. The problem is simply that the call to subprocess.call('py.test') is failing.


For future reference, this is the type of traceback you encounter when attempting to import a module that has not been installed:

>>> import foo
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named foo