pythonwindowspostgresqlsubprocesswindowserror

Why is subprocess.py throwing a WindowsError?


I'm trying to use the testing.postgresql package to test a few scripts and am running into this error upon instantiating testing.postgresql.Postgresql() or testing.postgresql.PostgresqlFactory():

File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\testing\common\database.py", line 83, in __init__
  self.initialize()
File "C:\Python27\lib\site-packages\testing\postgresql.py", line 50, in initialize
  self.initdb = find_program('initdb', ['bin'])
File "C:\Python27\lib\site-packages\testing\postgresql.py", line 134, in find_program
  path = get_path_of(name)
File "C:\Python27\lib\site-packages\testing\common\database.py", line 288, in get_path_of
  stderr=subprocess.PIPE).communicate()[0]
File "C:\Python27\lib\subprocess.py", line 710, in __init__
  errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 960, in _execute_child
  startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

From what I can find by following the trace and searching online, subprocess.py is failing to find initdb.exe. Exactly why is made murkier by subprocess.py handing off to an extension module, _subprocess.c.

I already tried adding the directory containing initdb to the system PATH, no dice.

Has anyone else experienced this issue, or any insight on what's going on here?


Solution

  • Viewing the source, it doesn't appear that this is compatible with Windows. The package expects a UNIX-style environment.

    testing.postgresql/src/testing/postgresql.py

    def find_program(name, subdirs):
         path = get_path_of(name)
         if path:
            return path
    
        for base_dir in SEARCH_PATHS:
            for subdir in subdirs:
                path = os.path.join(base_dir, subdir, name)
                if os.path.exists(path):
                    return path
    
         raise RuntimeError("command not found: %s" % name)
    

    testing.common.database

    def get_path_of(name):
         path = subprocess.Popen(['/usr/bin/which', name],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE).communicate()[0]
         if path:
             return path.rstrip().decode('utf-8')
         else:
             return None
    

    edited to show correct source of problem per @eryksun's comment below.