首页 > 解决方案 > Windows:使用 PostGres 时 Python 子进程“找不到指定的文件”

问题描述

我正在使用包pytest-server-fixtures在 Windows 上使用 PostGres 数据库进行测试。尝试访问 pg_config.exe 时包中出现问题:

subprocess.check_output(["pg_config", "--bindir"])

给出的错误:

The system cannot find the file specified

我知道这是一个相对常见的错误,但没有其他答案解决了这个问题。

我尝试过的事情:
• pg_config.exe 存在于 C:\Program Files\PostgreSQL\11\bin 中,并且已添加到我的 PATH 中。
pg_config --bindir在Python 之外运行会返回一个路径。
• 运行check_output不成功shell=True
• 运行check_output不成功shutil.which('pg_config')
• psycopg2 是在 PostGres 安装后安装的。
• 尝试使用 psycopg2-binary 失败。
• 这些测试是在 MacOS 上编写的,并且正在那里和 Linux 上成功运行。
• pg_config.exe 具有读取和执行权限。

任何帮助表示赞赏!谢谢!

标签: pythonwindowspostgresqlsubprocesspytest

解决方案


推荐阅读