答案1
不久前,我在 shell 脚本中添加了以下几行:
INSTALL=
for P in gnome-common yelp-tools yelp-xsl; do
if ! dpkg -l $P >/dev/null 2>&1; then
INSTALL="$INSTALL $P"
fi
done
if [ -n "$INSTALL" ]; then
echo "To use this script, please install required packages by running this command:"
echo "\nsudo apt install$INSTALL\n"
exit 1
fi
我认为同样的方法也适用于 Python 代码。