如何抑制pip升级警告?

per*_*oud 16 python pip

我的pip版本已关闭 - 每个pip命令都说:

You are using pip version 6.0.8, however version 8.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Run Code Online (Sandbox Code Playgroud)

而且我不喜欢这里给出的答案:我如何摆脱这个警告从pip升级?因为他们都希望pip与RH版本不同步.

所以我尝试使用这个VagrantFile进行干净的系统安装:

Vagrant.configure("2") do |config|

  config.ssh.username   = 'root'
  config.ssh.password   = 'vagrant'
  config.ssh.insert_key = 'true'

  config.vm.box = "bento/centos-7.3"

  config.vm.provider "virtualbox" do |vb|
    vb.cpus   = "4"
    vb.memory = "2048"
  end

  config.vm.synced_folder "..", "/vagrant"

  config.vm.network "public_network", bridge: "eth0", ip: "192.168.1.31"

  config.vm.provision "shell", inline: <<-SHELL
    set -x

    # Install pip
    yum install -y epel-release
    yum install -y python-pip
    pip freeze   # See if pip prints version warning on fresh OS install.

  SHELL

end
Run Code Online (Sandbox Code Playgroud)

但后来我得到了:

==> default: ++ pip freeze
==> default: You are using pip version 8.1.2, however version 9.0.1 is available.
==> default: You should consider upgrading via the 'pip install --upgrade pip' command.
Run Code Online (Sandbox Code Playgroud)

所以我似乎使用了错误的命令来安装pip.什么是正确的命令?

Joh*_*Mee 27

创建一个pip配置文件并设置disable-pip-version-check为true

[global]
disable-pip-version-check = True
Run Code Online (Sandbox Code Playgroud)

在很多linux上,pip配置文件的默认位置是$HOME/.config/pip/pip.conf.Windows,macOS和virtualenvs的位置太多了,无法在此处详述.请参阅文档:

https://pip.pypa.io/en/stable/user_guide/#config-file

  • 您可以运行“pip config set global.disable-pip-version-check true”,而不是编辑文件 (7认同)

小智 24

或者只使用命令行标志

pip --disable-pip-version-check [normal stuff here]
Run Code Online (Sandbox Code Playgroud)


Lev*_*von 20

只是添加到@sorin 的答案

在 Dockerfile 中添加这两行以禁用 pip 版本检查和缓存。

FROM python:3.6.10

ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PIP_NO_CACHE_DIR=1

RUN pip3 install -r requirements.txt
# ...
Run Code Online (Sandbox Code Playgroud)

  • 如果您的镜像在另一个 dockerfile 的 FROM 语句中使用,这是否意味着环境变量仍然存在于该镜像中?当使用“pip install”时,这会导致令人惊讶的行为。我想我不想更改 dockerfile 中的持久状态,因此我建议使用命令行参数:`RUN pip install --disable-pip-version-check --no-cache-dir -rrequirements.txt` (3认同)
  • @iron9 是的,这是正确的,但是您可以使用“ARG”而不是“ENV”来使环境变量仅在构建期间可用,而不是在实际图像中可用。例如`ARG PIP_NO_CACHE_DIR=1` (2认同)

sor*_*rin 14

另一种侵入性较小且未直接记录但完全支持的禁用版本检查的方法是定义:

export PIP_DISABLE_PIP_VERSION_CHECK=1
Run Code Online (Sandbox Code Playgroud)

  • 它是[“记录”](https://pip.pypa.io/en/stable/user_guide/#environment-variables),只是没有明确说明。 (2认同)