Docker: pg_config is required to build psycopg2 from source

我目前正在尝试构建一个默认带有 SSL 的 Django 应用程序,并借助 Lua Open Resty SSL 和 valian/docker-nginx-auto-ssl 镜像的帮助(请参阅此处的参考:https://github.com/Valian/docker-nginx-auto-ssl)。

我想将上述项目的 Dockerfile 与我的一个项目合并,在安装来自我的 requirements.txt 文件的 python 依赖项时遇到了问题:

psycopg2-binary==2.8.4

valian Dockerfile 中指定的基本操作系统是 Alpine,因此操作系统级别的依赖项是通过 apk 源获取的(FROM openresty/openresty:alpine-fat)。

我收到的具体错误是这样的:

Collecting psycopg2-binary==2.8.2
  Downloading https://files.pythonhosted.org/packages/dc/93/bb5655730913b88f9068c6b596177d1df83be0d476671199e17b06ea8436/psycopg2-binary-2.8.2.tar.gz (369kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/local/lib/pyenv/versions/3.8.0/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6t5fbphg/psycopg2-binary/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6t5fbphg/psycopg2-binary/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-6t5fbphg/psycopg2-binary/pip-egg-info
         cwd: /tmp/pip-install-6t5fbphg/psycopg2-binary/
    Complete output (23 lines):
    running egg_info
    creating /tmp/pip-install-6t5fbphg/psycopg2-binary/pip-egg-info/psycopg2_binary.egg-info
    writing /tmp/pip-install-6t5fbphg/psycopg2-binary/pip-egg-info/psycopg2_binary.egg-info/PKG-INFO
    writing dependency_links to /tmp/pip-install-6t5fbphg/psycopg2-binary/pip-egg-info/psycopg2_binary.egg-info/dependency_links.txt
    writing top-level names to /tmp/pip-install-6t5fbphg/psycopg2-binary/pip-egg-info/psycopg2_binary.egg-info/top_level.txt
    writing manifest file '/tmp/pip-install-6t5fbphg/psycopg2-binary/pip-egg-info/psycopg2_binary.egg-info/SOURCES.txt'

    Error: pg_config 可执行文件未找到。

    构建 psycopg2 需要 pg_config,请将包含 pg_config 的目录添加到 $PATH 或使用以下选项指定完整的可执行文件路径:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    或在 'setup.cfg' 中使用 pg_config 选项。

    如果您更喜欢避免从源代码构建 psycopg2,请安装 PyPI 'psycopg2-binary' 包。

    有关更多信息,请查看 'doc/src/install.rst' 文件(也可在<http://initd.org/psycopg/docs/install.html>中找到)。

    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

如果我使用 psycopg2==2.8.4,也会发生这种情况。

那么,我需要做什么才能为容器提供 pg_config 可执行文件呢?这是 apk add postgresql 自带的吗?

相关问题pg_config 可执行文件未找到

点赞