Rit*_*ata 6 python caching requirements pip docker
我正在尝试使用一堆 python 库创建一个 docker 映像。
在执行 a 时pip install --no-cache-dir -r requirements.txt
,它会因库(尤其是 pyspark)的哈希值不匹配而失败。
失败消息看起来像 -
ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
pyspark==2.4.6 from https://files.pythonhosted.org/packages/e9/e4/5c15ab8d354c4e3528510821865e6748209a9b0ff6a1788f4cd36cc2a5dc/pyspark-2.4.6.tar.gz#sha256=b4b319a3ffd187a3019f654ae1c8ac38048bcec2940f8cecdef829302d166feb (from -r requirements.txt (line 4)):
Expected sha256 b4b319a3ffd187a3019f654ae1c8ac38048bcec2940f8cecdef829302d166feb
Got e15b72fe55a366df7329932882c56328874152cf618950c7ce45e11f1c9dc5d1
Run Code Online (Sandbox Code Playgroud)
我已经尝试过的一些东西,咨询其他堆栈溢出线程 -
__pycache__
和~/.cache/
目录。--no-cache-dir
如您所见。docker build --no-cache . -t labydock-image
Dockerfile 看起来像这样 -
FROM python:3.7.7-stretch
USER root
RUN apt-get update && apt-get install -y --no-install-recommends openjdk-8-jdk
WORKDIR /labyrinth
COPY ./dodo.py .
COPY ./requirements.txt .
RUN pip install pip==20.0.2
RUN rm -rf ~/.cache
RUN rm -rf __pycache__
RUN pip install --no-cache-dir -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
相应的requirements.txt文件如下所示 -
mockito==1.2.1
py4j==0.10.7
pypandoc==1.5
pyspark==2.4.6
pytest
pandas
doit
koalas
requests
presto-client
mysql-connector-python
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。如果您需要更多详细信息,请告诉我
经过深思熟虑,我在同事的帮助下解决了这个问题。
我们的根本原因分析如下 - 当我们下载库时,服务器本身会发送 SHA 进行下载后验证,以防止篡改库。现在,由于互联网连接不佳,下载时库被损坏,因此发生了 sha 不匹配的情况。这对我来说听起来非常奇怪,因为我认为 pip 会检测到此故障并提示库下载失败。
不管怎样,我们在虚拟机上运行了相同的 docker 镜像,它的效果非常好。
归档时间: |
|
查看次数: |
2097 次 |
最近记录: |