[英]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的評論顯示問題的正確來源。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.