gpt4 book ai didi

python - Docker 无法将 psycopg2-binary 识别为 psycopg2

转载 作者:行者123 更新时间:2023-12-04 19:05:40 29 4
gpt4 key购买 nike

使用 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"]
脚本.py:
import psycopg2

print('it is ok')
点文件:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
psycopg2-binary = "*"

[dev-packages]

[requires]
python_version = "3.8"
它适用于这样的配置。

关于python - Docker 无法将 psycopg2-binary 识别为 psycopg2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70686829/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com