python - 为什么在Dockerfile中使用requirements.txt中的 pip `install_requires`从setup.py安装 “.”失败?

标签 python docker pip setup.py

我正在尝试使用here描述的方法
Docker文件

FROM python:3.8

COPY requirements.txt setup.py /tmp/
RUN pip3 install -r /tmp/requirements.txt \
    && rm /tmp/*
这失败与:
Step 1/7 : FROM python:3.8
 ---> 79cc46abd78d
Step 2/7 : COPY requirements.txt setup.py /tmp/
 ---> Using cache
 ---> a50a0a8ecb06
Step 3/7 : RUN pip3 install -r /tmp/requirements.txt     && rm /tmp/*
 ---> Running in c7d29bd8f23c
ERROR: Directory '.' is not installable. Neither 'setup.py' nor 'pyproject.toml'
 found.
我也尝试注释掉RUN命令,进入容器并运行
手动输入pip3 install -r /tmp/requirements.txt。这工作没有错误。
我不知道这里可能是什么问题。

最佳答案

我想到了:
.不是相对于requirements.txt而是相对于当前工作目录。当我手动执行时它起作用的原因是,我还将我的工作空间安装到了一个devcontainer中,并在该工作空间中包含了setup.py的工作目录。
因此,解决方案是执行以下操作:

WORKDIR /tmp
COPY requirements.txt setup.py ./
RUN pip3 install -r requirements.txt \
    && rm /tmp/*

关于python - 为什么在Dockerfile中使用requirements.txt中的 pip `install_requires`从setup.py安装 “.”失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63595467/

相关文章:

python - 查找列表中最大的匹配项

python - 如何安装 "SpaCy"库而不出现此错误?

python - Django "no module named myapp.models"

python - 在句子中正确使用a或an

docker - 为什么 Loki 的 Docker Driver Client 在一段时间后停止记录?

mysql - Kubernetes:不允许主机 'x.x.x.x' 连接到此 MySQL

python - 无法使用 python3 和 sqlite3 安装 pyspatialite

centos - python virtualenvwrapper 类型错误 : __init__() got an unexpected keyword argument 'stream'

python - flask 棉花糖/SqlAlchemy : Serializing many-to-many relationships

docker - 无法从使用docker-compose up运行的React应用程序获得任何响应