How to prevent accidentally calling pip when I am not in a virtualenv?
I wrote the following script called pip
and added it to my ~/bin
(which is before pip in my $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
Is there a better way?