作为我的Bash脚本的一部分,我想以非交互模式安装和卸载我在文件中拥有名称的pip依赖项。我能够搜索并找到这些命令:
pip3 uninstall --yes -r host-requirements.txt
pip3 install --no-input -r host-requirements.txt
我在pip的帮助文档中找不到--yes
和--no-input
选项,也不确定它们是否得到官方支持。
卸载时,您可以像这里描述的那样使用--yes
或-y
标志:https://pip.pypa.io/en/stable/cli/pip_uninstall/
安装时,您可以传递yes | pip install -r requirements.txt
,如此处所述:python pip silent install
希望这能帮到您。
yes
应该适用于 pip 安装。当你想要确认服务器的真实性时,像示例中那样使用它是行不通的。 - Anurag Saxenapip install -r
是否可能陷入这种情况? - Arian有更多的互动问题期望得到除了“是”以外的其他答案。例如:
Directory /opt/services/spam/egg already exists, and is not a git clone.
What to do? (i)gnore, (w)ipe, (b)ackup`
echo "i" | pip install ...
就足够了。Obtaining file://...
Collecting your_private_package@ git+ssh://...
Cloning ssh://****@.../
Running command git clone -q 'ssh://****@.../
The authenticity of host can't be established.
RSA key fingerprint is ...
Are you sure you want to continue connecting (yes/no)?
为此,ssh StrictHostKeyChecking
将被暂时设置为 no。这可以在主机或用户级别上完成,但会降低安全性风险。
--no-input
https://github.com/pypa/pip/blob/master/src/pip/_internal/cli/cmdoptions.py#L219 和--yes
在这里 https://github.com/pypa/pip/blob/master/src/pip/_internal/commands/uninstall.py#L39。 - pawelbylina