本文介绍了无法在新的停靠容器上安装心理备份2-二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试在新的Docker容器上运行Django项目时遇到了一个问题。这是我第一次使用Docker,我似乎找不到在它上运行Django项目的好方法。尝试了多个教程后,我总是收到有关未安装心理备份2的错误消息。

Requirements s.txt:

-i https://pypi.org/simple
asgiref==3.2.7
django-cors-headers==3.3.0
django==3.0.7
djangorestframework==3.11.0
gunicorn==20.0.4
psycopg2-binary==2.8.5
pytz==2020.1
sqlparse==0.3.1

Dockerfile:

# pull official base image
FROM python:3.8.3-alpine

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install dependencies
RUN pip install --upgrade pip

COPY ./requirements.txt .
RUN pip install -r requirements.txt

# copy project
COPY . .

# set project environment variables
# grab these via Python's os.environ
# these are 100% optional here

ENV PORT=8000
ENV SECRET_KEY_TWITTER = "***"

运行docker-compose版本时,我收到以下错误:

Error: pg_config executable not found.

pg_config is required to build psycopg2 from source. Please add the directory

containing pg_config to the $PATH or specify the full executable path with the

option:

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

or with the pg_config option in 'setup.cfg'.

If you prefer to avoid building psycopg2 from source, please install the PyPI

'psycopg2-binary' package instead.

我很乐意回答任何可能导致解决方案的问题。另外,也许有人可以向我推荐一个关于Django应用程序停靠的好教程?

推荐答案

在阿尔卑斯Linux上,您将需要编译所有包,即使在PYPI上有预编译的二进制轮子也是如此。在标准的基于Linux的映像上,您不会(https://pythonspeed.com/articles/alpine-docker-python/--我在那里写的其他文章可能会有所帮助,例如关于安全的)。

因此将您的基本图像更改为python:3.8.3-slim-busterpython:3.8-slim-buster,它应该会起作用。

这篇关于无法在新的停靠容器上安装心理备份2-二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 09:45