[英]Python requests RequestsDependencyWarning which disappears after re-installing the same version of the library
I'm building a python environment within a docker container using a Dockerfile.我正在使用 Dockerfile 在 docker 容器内构建 python 环境。 One of the levels is to pip install a requirements.txt file which includes the following libraries:其中一个级别是 pip 安装一个 requirements.txt 文件,其中包括以下库:
chardet==3.0.4
requests==2.22.0
urllib3==1.25.6
After the image has been built I create a container instance and run the following inside it: python -c "import requests"
which gives the following output:构建映像后,我创建一个容器实例并在其中运行以下命令: python -c "import requests"
给出以下 output:
/usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.25.6) or chardet (2.2.1) doesn't match a supported version! RequestsDependencyWarning)
Fair enough, however if I reinstall requests, pip install --upgrade requests --force-reinstall
, and run the same python command above I don't receive the warning.很公平,但是如果我重新安装请求, pip install --upgrade requests --force-reinstall
并运行上面相同的 python 命令,我不会收到警告。
I can check the versions of each library again within the container and they're exactly the same as before:我可以在容器中再次检查每个库的版本,它们与以前完全相同:
chardet==3.0.4
requests==2.22.0
urllib3==1.25.6
So why would requests
have been issuing the error before, and how can I ensure this warning doesn't come up within my Docker image without having a dangling re-install level in my Dockerfile?那么,为什么requests
之前会发出错误,以及如何确保在我的 Dockerfile 中没有悬空的重新安装级别的情况下,此警告不会出现在我的 Docker 映像中?
I haven't found any adverse affects so far while using requests
within my code while the warning is popping-up, however I'd rather it not be there since something is obviously triggering it.到目前为止,在弹出警告时在我的代码中使用requests
时,我没有发现任何不利影响,但是我宁愿它不存在,因为显然有什么东西在触发它。
I've found a number of posts/articles that suggest just sticking with re-installing requests
, however I wouldn't want this redundant step within the Dockerfile unless it was the only way to resolve the warning.我发现许多帖子/文章建议只坚持重新安装requests
,但是我不希望 Dockerfile 中的这个冗余步骤,除非它是解决警告的唯一方法。
Interestingly reinstalling chardet
also removes the warning however reinstalling urllib3
does not.有趣的是,重新安装chardet
也会删除警告,但重新安装urllib3
不会。
-- edit -- Dockerfile as requested: -- 编辑 -- Dockerfile 按要求:
FROM centos:7
# Install external yum repositories
RUN yum install -y \
epel-release \
https://repo.ius.io/ius-release-el7.rpm \
&& yum clean all
# Install required rpm dependencies
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python get-pip.py
RUN yum install -y \
systemd-python.x86_64 \
git222 \
gcc \
python2-devel \
openldap-devel \
python-perf \
python-linux-procfs \
python-schedutils \
policycoreutils-python \
python-slip \
python-slip-dbus \
&& yum clean all
# Install required pip dependencies
ADD requirements.txt /home/admin/container_files/
RUN pip install setuptools==30.1.0
RUN pip install -r /home/admin/container_files/requirements.txt
# Final update of packages
RUN yum update -y && yum clean all
the workaround will be to re-order the install in your file to:解决方法是将文件中的安装重新排序到:
chardet==3.0.4
urllib3==1.25.6
requests==2.22.0
now python -c "import requests"
will work from the first time现在python -c "import requests"
将从第一次开始工作
and I suggest you to move:我建议你搬家:
RUN yum update -y && yum clean all
to second line, then that will be cached if you edit some of your later code.到第二行,如果您编辑一些以后的代码,它将被缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.