【问题标题】:psycopg2-binary failing to install in docker containerpsycopg2-binary 无法安装在 docker 容器中
【发布时间】:2021-04-06 13:53:23
【问题描述】:

为新手问题道歉。我在这里尝试了其他问题的所有答案,但也没有得到回报。

使用 Postgres 对我的 python/django 应用程序进行 Dockerizing 证明......令人生畏。我收到错误“错误:找不到 pg_config 可执行文件”。当它开始通过我的 requirements.txt 工作时始终如一

这是 Dockerfile:

FROM python:3.8.3-slim-buster
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD ./ /code/

...还有我的 requirements.txt...

asgiref==3.3.1
Django==3.1.4
psycopg2-binary==2.7.4
pytz==2020.5
sqlparse==0.4.1
django-compressor>=2.2
django-libsass>=0.7

和 docker-compose.yml

v ersion: "3.9"
   
services:
  db:
    image: postgres
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    volumes: 
      - pgdata:/var/lib/postgresql/data
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

volumes: 
  pgdata:

当我运行 docker-compose up --build 时,我一遍又一遍地收到此错误:

Step 6/7 : RUN pip install -r requirements.txt
 ---> Running in e0fd67d2d935
Collecting asgiref==3.3.1
  Downloading asgiref-3.3.1-py3-none-any.whl (19 kB)
Collecting Django==3.1.4
  Downloading Django-3.1.4-py3-none-any.whl (7.8 MB)
Collecting psycopg2-binary==2.7.4
  Downloading psycopg2-binary-2.7.4.tar.gz (426 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-fha1c65p/psycopg2-binary/setup.py'"'"'; __file__='"'"'/tmp/pip-install-fha1c65p/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-pip-egg-info-ewxlxmh6
         cwd: /tmp/pip-install-fha1c65p/psycopg2-binary/
    Complete output (23 lines):
    running egg_info
    creating /tmp/pip-pip-egg-info-ewxlxmh6/psycopg2_binary.egg-info
    writing /tmp/pip-pip-egg-info-ewxlxmh6/psycopg2_binary.egg-info/PKG-INFO
    writing dependency_links to /tmp/pip-pip-egg-info-ewxlxmh6/psycopg2_binary.egg-info/dependency_links.txt
    writing top-level names to /tmp/pip-pip-egg-info-ewxlxmh6/psycopg2_binary.egg-info/top_level.txt
    writing manifest file '/tmp/pip-pip-egg-info-ewxlxmh6/psycopg2_binary.egg-info/SOURCES.txt'
    
    Error: pg_config executable not found.

【问题讨论】:

  • 嗨,有趣,也许这可能是有趣的stackoverflow.com/questions/11618898/…
  • 你能展示你的 docker-compose 吗?
  • Danizavtz:版本:“3.9”服务:db:图像:postgres 环境:- POSTGRES_DB=postgres - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres 卷:- pgdata:/var/lib/postgresql/data web : 建造: 。命令:python manage.py runserver 0.0.0.0:8000 卷:-.:/code 端口:-“8000:8000”depends_on:-db 卷:pgdata:

标签: python django postgresql docker docker-compose


【解决方案1】:

最终,答案似乎是在我的 Dockerfile 中的几件事中找到的,但是……最终……从 Python 3.8 降级到 3.7 解锁了一切。

FROM python:3.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/

RUN apt-get update
RUN apt-get install -y postgresql 
RUN apt-get install libpq-dev gcc
RUN export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH
RUN apt-get install -y python3-dev
RUN apt-get install -y python3-psycopg2 

RUN pip3 install -r requirements.txt
ADD ./ /code/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-06
    • 2017-07-14
    • 1970-01-01
    • 2015-03-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 2020-12-11
    相关资源
    最近更新 更多