使用pip安装时挂在包许可协议上

2 投票
1 回答
879 浏览
提问于 2025-04-18 09:45

我公司要求在我们发布一个Python包的时候,必须附上一个许可协议,安装者在安装之前必须同意这个协议。有没有办法让pip变得互动一些呢?

举个例子:

pip install mypackage

别搞小动作!

你同意这些条款吗? : y

然后pip安装继续进行....

1 个回答

1

你试过用 yes 命令吗?

yes | pip install mypackage

补充:

我觉得 pip 可能做不到这个,但你可以写个脚本来实现:

cat license.txt
read -p "Do you agree to the terms? " -n 1 -r
echo    # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
    pip install mypackage
fi

这段内容是从 https://stackoverflow.com/a/1885534/1178781 偷来的

撰写回答