【发布时间】:2021-11-23 07:55:18
【问题描述】:
我非常努力地在 pypy3 docker image https://hub.docker.com/_/pypy 上安装 psycopg2
事实证明这是不可能的......
FROM pypy:3
WORKDIR /
COPY . .
RUN apt-get update
RUN apt-get install libpq-dev gcc
RUN apt-get -y install python3-dev
RUN apt-get -y install postgresql
RUN apt-get -y install gcc
RUN pypy3 -m pip install --upgrade pip
RUN pypy3 -mpip install psycopg2 <-- Blow up here
RUN pypy3 -mpip install -r requirements.txt
ENV PATH /opt/conda/bin:$PATH
ENV PYTHONPATH "${PYTHONPATH}:/src"
ENTRYPOINT ["pypy3", "xxx.py"]
错误信息是:
api_gateway_1 | File "/opt/pypy/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 793, in dbapi
api_gateway_1 | import psycopg2
api_gateway_1 | ModuleNotFoundError: No module named 'psycopg2'
esql -I/usr/include/postgresql/13/server -I/usr/include/libxml2 -c psycopg/typecast.c -o build/temp.linux-x86_64-3.7/psycopg/typecast.o -Wdeclaration-after-statement
#8 1044.6 In file included from psycopg/typecast.c:168:
#8 1044.6 ./psycopg/typecast_datetime.c: In function ‘_parse_inftz’:
#8 1044.6 ./psycopg/typecast_datetime.c:116:14: error: ‘PyDateTime_TimeZone_UTC’ undeclared (first use in this function); did you mean ‘PyDateTime_Time’?
#8 1044.6 116 | tzinfo = PyDateTime_TimeZone_UTC;
#8 1044.6 | ^~~~~~~~~~~~~~~~~~~~~~~
#8 1044.6 | PyDateTime_Time
#8 1044.6 ./psycopg/typecast_datetime.c:116:14: note: each undeclared identifier is reported only once for each function it appears in
#8 1044.6 error: command 'gcc' failed with exit status 1
我尝试了不同的方法,但都没有奏效。 https://blog.csdn.net/cdnight/article/details/52536451 https://cloud.tencent.com/developer/ask/119621 Installing psycopg2 command 'gcc' failed with exit status 1
最后,我(不情愿地)通过切换到 anaconda 作为基础映像来管理:
FROM continuumio/anaconda3
WORKDIR /
COPY . .
RUN apt-get update
RUN apt-get -y install libpq-dev gcc
RUN apt-get -y install python3-dev
RUN apt-get -y install postgresql
RUN apt-get -y install gcc
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
ENV PATH /opt/conda/bin:$PATH
ENV PYTHONPATH "${PYTHONPATH}:/src"
ENTRYPOINT ["python", "xxx.py"]
注意,这些在 dockerfile 中:
RUN apt-get -y install libpq-dev gcc
RUN apt-get -y install python3-dev
RUN apt-get -y install postgresql
RUN apt-get -y install gcc
都是针对sqlalchemy,依赖psycopg2,依赖configparser:
configparser
psycopg2
sqlalchemy
成功了。但我真的很想要pypy3。
【问题讨论】:
标签: python-3.x sqlalchemy psycopg2 pypy