Python请求RequestsPendencyWarning,该警告在重新安装相同版本的库后消失

Python请求RequestsPendencyWarning,该警告在重新安装相同版本的库后消失,python,docker,pip,centos,dockerfile,Python,Docker,Pip,Centos,Dockerfile,我正在使用Dockerfile在docker容器中构建python环境。其中一个级别是pip安装requirements.txt文件,该文件包括以下库: chardet==3.0.4 requests==2.22.0 urllib3==1.25.6 构建映像后,我创建一个容器实例,并在其中运行以下操作: python-c“导入请求” 这将提供以下输出: /usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDepen

我正在使用Dockerfile在docker容器中构建python环境。其中一个级别是pip安装requirements.txt文件,该文件包括以下库:

chardet==3.0.4
requests==2.22.0
urllib3==1.25.6
构建映像后,我创建一个容器实例,并在其中运行以下操作:
python-c“导入请求”
这将提供以下输出:

/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)
不过,如果我重新安装请求,
pip install--upgrade requests--force reinstall
,并运行上面相同的python命令,我不会收到警告

我可以在容器中再次检查每个库的版本,它们与以前完全相同:

chardet==3.0.4
requests==2.22.0
urllib3==1.25.6
那么,
请求
之前为什么会发出错误,我如何确保在Docker映像中不会出现此警告,而我的Docker文件中没有悬空的重新安装级别

到目前为止,当警告弹出时,在我的代码中使用
请求时,我还没有发现任何负面影响,但是我宁愿它不在那里,因为显然有什么东西触发了它

我发现许多帖子/文章建议只需重新安装
请求
,但是我不希望在Dockerfile中重复这一步骤,除非这是解决警告的唯一方法

有趣的是,重新安装
chardet
也会删除警告,但是重新安装
urlib3
不会

--编辑-- 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

解决方法是将文件中的安装重新排序为:

chardet==3.0.4
urllib3==1.25.6
requests==2.22.0
现在
python-c“导入请求”
将从第一次开始工作

我建议你搬家:

RUN yum update -y && yum clean all

到第二行,然后如果您编辑一些以后的代码,它将被缓存。

我认为这与python和pip版本有关,您可以使用python base image来确保它们的版本正确感谢您的建议,尽管基本python映像是基于debian的,而我需要centos7 base。Centos7附带Python2.7.5+,我已经安装了pip的最新(推荐?)版本,该版本来自pip自己的网站。我希望这两个不是不相容的!你可以使用这个或任何你想要的版本。好的,我已经尝试过这个基本图像,但是它在我的项目中有很多问题!我发现在基础centos7图像上取得了更大的成功。谢谢你,已经做到了!不知何故,我没有尝试像那样重新排序requirements.txt列表。。!?还感谢docker提示-我相应地修改了docker文件:)