Skip to content

Instantly share code, notes, and snippets.

@jin10086
Created March 25, 2026 01:19
Show Gist options
  • Select an option

  • Save jin10086/f3cc120b4b54c4d591a81270adda2311 to your computer and use it in GitHub Desktop.

Select an option

Save jin10086/f3cc120b4b54c4d591a81270adda2311 to your computer and use it in GitHub Desktop.
clean_env.sh
#!/bin/bash
# 1. 定义要清理的毒包名称
TARGET_PACKAGE="litellm"
echo "正在获取所有 Conda 环境列表..."
# 2. 获取所有环境的路径(跳过注释行,提取路径列)
# conda env list 的输出格式通常是: name * /path/to/env
ENV_PATHS=$(conda env list | grep -v '^#' | awk '{print $NF}')
for env_path in $ENV_PATHS; do
# 检查路径下是否存在 python 执行文件
if [[ -f "$env_path/bin/python" ]]; then
PYTHON_EXE="$env_path/bin/python"
elif [[ -f "$env_path/python.exe" ]]; then
# 兼容 Windows 路径
PYTHON_EXE="$env_path/python.exe"
else
continue
fi
echo "------------------------------------------------"
echo "正在检测环境: $env_path"
# 3. 检测包是否存在
$PYTHON_EXE -m pip show $TARGET_PACKAGE > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "[!] 警告:在环境 $env_path 中发现 $TARGET_PACKAGE"
# 4. 执行卸载
echo "[*] 正在卸载 $TARGET_PACKAGE..."
$PYTHON_EXE -m pip uninstall $TARGET_PACKAGE -y
# 5. 清理该环境的 pip 缓存
echo "[*] 正在清理该环境的 pip 缓存..."
$PYTHON_EXE -m pip cache purge
echo "[OK] 环境 $env_path 处理完毕。"
else
echo "[-] 未发现风险包。"
fi
done
echo "------------------------------------------------"
echo "全局清理完成。建议检查环境变量是否有异常。"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment