首页 > 解决方案 > 当我使用 pip install psycopg2 构建 docker 时出现错误

问题描述

the error: 

Skipping optional fixer: ws_comma
running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/psycopg
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.7.3.1 (dt dec pq3 ext lo64)" -DPG_VERSION_NUM=110500 -DHAVE_LO64=1 -I/usr/local/include/python3.8 -I. -I/usr/include/postgresql -I/usr/include/postgresql/11/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.8/psycopg/psycopgmodule.o -Wdeclaration-after-statement
psycopg/psycopgmodule.c: In function ‘psyco_is_main_interp’:
psycopg/psycopgmodule.c:685:18: error: dereferencing pointer to incomplete type ‘PyInterpreterState’ {aka ‘struct _is’}
     while (interp->next)
                  ^~
error: command 'gcc' failed with exit status 1

当我构建 dockerc-compose 来 pip install psycopg2 并遇到问题时。

Dockerfile:

RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list
RUN cat /etc/apt/sources.list
RUN apt-get clean  && apt-get update

RUN apt-get install -y python3-dev \
    && apt-get install -y libevent-dev \
    && pip install --default-timeout=1000 --no-cache-dir -r requirements.txt

标签: pythondockerpsycopg2

解决方案


您正在尝试构建 psycopg2 版本 2.7.3.1:该版本与 Python 3.8 不兼容。

您必须使用至少 2.8.4 的 psycopg2 版本。

https://www.psycopg.org/docs/news.html#what-s-new-in-psycopg-2-8-4


推荐阅读