You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker构建时pip无法找到psycopg2-binary版本的问题求助

问题:构建Airflow镜像时提示无法找到psycopg2-binary包版本

问题场景

使用以下Dockerfile构建Airflow镜像:

FROM nexus3/docker-hub/apache/airflow:slim-2.10.0-python3.11

ENV PIP_CONFIG_FILE=/home/airflow/pip.conf
ENV AIRFLOW_VERSION=2.10.0

RUN --mount=type=secret,id=pip,target=/home/airflow/pip.conf,uid=50000,required=true \
    --mount=type=bind,source=requirements.txt,target=requirements.txt \
    pip install --no-cache-dir "apache-airflow[celery,postgres,statsd]==${AIRFLOW_VERSION}" -r requirements.txt

执行构建命令:

docker build -t nexus3.systems.uk.hsbc:18094/docker-hub/11976246/apache/airflow:slim-2.10.0-python3.11 --secret id=pip,src=pip.conf .

requirements.txt内容:

requests
httpx
psycopg2-binary
psycopg[binary,pool]
oracledb
pyxlsb
pandas
polars
statsd

构建时出现错误:

1.769 Requirement already satisfied: requests in /home/airflow/.local/lib/python3.11/site-packages (from -r requirements.txt (line 1)) (2.32.3)
1.769 Requirement already satisfied: httpx in /home/airflow/.local/lib/python3.11/site-packages (from -r requirements.txt (line 2)) (0.27.0)
2.625 ERROR: Could not find a version that satisfies the requirement psycopg2-binary (from versions: none)
3.520 ERROR: No matching distribution found for psycopg2-binary

原因分析

  1. 包已被弃用:psycopg2-binary是psycopg2系列的二进制包,psycopg3(即psycopg)发布后,官方不再维护psycopg2-binary的新版本,且针对Python 3.11的psycopg2-binary包可能未发布或未同步到你的私有pip源中。
  2. 依赖冗余冲突:同时指定psycopg2-binary和psycopg[binary,pool]属于重复配置,后者是psycopg3的二进制版本(已包含连接池功能),完全可替代前者。

解决办法

  1. 移除冗余依赖:删除requirements.txt中的psycopg2-binary行,保留psycopg[binary,pool]即可满足PostgreSQL连接需求。修改后的requirements.txt:
requests
httpx
psycopg[binary,pool]
oracledb
pyxlsb
pandas
polars
statsd
  1. 检查pip源配置:确认pip.conf中配置的私有源已同步psycopg包,若未包含,需添加官方PyPI源或确保镜像能访问到包含该包的有效源。

  2. 兼容性验证:Airflow 2.8及以上版本已支持psycopg3,你使用的2.10.0版本完全兼容,无需担心版本适配问题。

内容的提问来源于stack exchange,提问作者moth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 03:05:03