为什么 subprocess.py 抛出 WindowsError?
Why is subprocess.py throwing a WindowsError?
我正在尝试使用 testing.postgresql 包来测试一些脚本,并且 运行 在实例化 testing.postgresql.Postgresql() 或 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
根据我跟踪跟踪和在线搜索的结果,subprocess.py 找不到 initdb.exe。 subprocess.py 移交给扩展模块 _subprocess.c 的确切原因变得更加模糊。
我已经尝试将包含 initdb 的目录添加到系统 PATH 中,不行。
有没有其他人遇到过这个问题,或者对这里发生的事情有任何见解?
查看源代码,这似乎与 Windows 不兼容。该软件包需要一个 UNIX 风格的环境。
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)
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
编辑 以根据@eryksun 下面的评论显示正确的问题来源。
我正在尝试使用 testing.postgresql 包来测试一些脚本,并且 运行 在实例化 testing.postgresql.Postgresql() 或 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
根据我跟踪跟踪和在线搜索的结果,subprocess.py 找不到 initdb.exe。 subprocess.py 移交给扩展模块 _subprocess.c 的确切原因变得更加模糊。
我已经尝试将包含 initdb 的目录添加到系统 PATH 中,不行。
有没有其他人遇到过这个问题,或者对这里发生的事情有任何见解?
查看源代码,这似乎与 Windows 不兼容。该软件包需要一个 UNIX 风格的环境。
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)
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
编辑 以根据@eryksun 下面的评论显示正确的问题来源。