Docker 无法将 psycopg2-binary 识别为 psycopg2

Docker not recognising psycopg2-binary as psycopg2

使用 pipenv 我有以下 pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "*"
uuid = "*"
gunicorn = "*"
psycopg2-binary = "*"

[dev-packages]

[requires]
python_version = "3.8"

然后我的Dockerfile设置如下:

FROM python:3.8.3-slim-buster

RUN useradd deploy_trial

WORKDIR /home/deploy_trial

RUN pip install pipenv

COPY . /home/deploy_trial/

RUN pipenv install --deploy

CMD ["python","./app/text.py"]

然而,虽然构建似乎成功,但当我 运行 图像时,我收到一条错误消息:

Traceback (most recent call last):
  File "./app/text.py", line 1, in <module>
    import psycopg2
ModuleNotFoundError: No module named 'psycopg2'

所以它显然认为 psycopg2 还没有安装...这真的很奇怪,因为当我在我的本地机器上使用 psycopg2-binary 并且我的所有程序都将安装识别为 psycopg2 当代码是运行。有谁知道如何解决这个问题?

我的 docker 文件:

FROM python:3.8.3-slim-buster

RUN python -m pip install pipenv

COPY script.py script.py
COPY Pipfile Pipfile
RUN pipenv install

CMD ["pipenv", "run", "python", "script.py"]

script.py:

import psycopg2

print('it is ok')

Pip文件:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
psycopg2-binary = "*"

[dev-packages]

[requires]
python_version = "3.8"

它适用于这样的配置。