当我不在 virtualenv 中时,如何防止意外调用 pip?
我编写了以下脚本调用pip
并将其添加到我的~/bin
(在我的 pip 之前$PATH
):
# This script makes sure I don't accidentally install pip without virtualenv
# This script requires $PIP to be set to the absolute path of pip to execute pip
# if $PIP is not set, it will write a message
if [ -z "$PIP" ]; then
echo "you are not in a virtual env"
echo "use virtual env or"
# propose the second item in $PATH
echo " export PIP="`type -ap pip|sed -n 2p`
echo "to cleanup use"
echo " unset PIP"
else
# execute pip
exec $PIP "$@"
fi
有没有更好的办法?