|
| 1 | +# Python Environment Reset Tool | Python 环境重置工具 |
| 2 | + |
| 3 | +[English](#english) | [中文](#chinese) |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +<a name="english"></a> |
| 8 | +## 🌟 English |
| 9 | + |
| 10 | +### Overview |
| 11 | + |
| 12 | +A lightweight Windows batch script tool for safely resetting Python virtual environments. It automatically detects and activates virtual environments, uninstalls all packages, and reinstalls essential base packages. |
| 13 | + |
| 14 | +### ✨ Features |
| 15 | + |
| 16 | +- 🔍 **Auto-Detection**: Automatically detects common virtual environment directories (`.venv`, `venv`, `env`, `.env`) |
| 17 | +- 🛡️ **Safety First**: Warns users when operating on global Python environment |
| 18 | +- 📦 **Clean Reset**: Uninstalls all packages and reinstalls base packages (pip, setuptools, wheel) |
| 19 | +- 🎯 **User-Friendly**: Clear prompts and confirmations before any destructive operations |
| 20 | +- 🌐 **UTF-8 Support**: Properly handles Chinese and other Unicode characters |
| 21 | + |
| 22 | +### 📋 Requirements |
| 23 | + |
| 24 | +- Windows OS |
| 25 | +- Python 3.x installed and accessible via `python` command |
| 26 | +- pip package manager |
| 27 | + |
| 28 | +### 🚀 Quick Start |
| 29 | + |
| 30 | +1. **Download** the `env-reset.bat` file |
| 31 | +2. **Place** it in your Python project root directory (where your virtual environment folder is) |
| 32 | +3. **Run** by double-clicking `env-reset.bat` or executing it in command prompt |
| 33 | + |
| 34 | +```batch |
| 35 | +env-reset.bat |
| 36 | +``` |
| 37 | + |
| 38 | +### 📖 Usage |
| 39 | + |
| 40 | +#### For Virtual Environment (Recommended) |
| 41 | + |
| 42 | +```bash |
| 43 | +# Create a virtual environment first (if you haven't) |
| 44 | +python -m venv .venv |
| 45 | + |
| 46 | +# Run the reset tool |
| 47 | +env-reset.bat |
| 48 | +``` |
| 49 | + |
| 50 | +The script will: |
| 51 | +1. Detect and activate your virtual environment |
| 52 | +2. List all installed packages |
| 53 | +3. Ask for confirmation |
| 54 | +4. Uninstall all packages |
| 55 | +5. Upgrade pip and install base packages |
| 56 | + |
| 57 | +#### For Global Environment (Not Recommended) |
| 58 | + |
| 59 | +If no virtual environment is detected, the script will: |
| 60 | +1. Display a **strong warning** |
| 61 | +2. Require explicit confirmation (type `YES` in uppercase) |
| 62 | +3. Proceed only if confirmed |
| 63 | + |
| 64 | +### 🔧 Supported Virtual Environment Names |
| 65 | + |
| 66 | +- `.venv` (recommended) |
| 67 | +- `venv` |
| 68 | +- `env` |
| 69 | +- `.env` |
| 70 | + |
| 71 | +### ⚠️ Important Notes |
| 72 | + |
| 73 | +- **Always use virtual environments** for project development |
| 74 | +- The script will **not** delete the virtual environment folder itself |
| 75 | +- Base packages (pip, setuptools, wheel) are automatically reinstalled |
| 76 | +- If `requirements.txt` exists, you'll be reminded to reinstall project dependencies |
| 77 | + |
| 78 | +### 📝 Example Output |
| 79 | + |
| 80 | +``` |
| 81 | +========================================== |
| 82 | + 虚拟环境重置工具 |
| 83 | +========================================== |
| 84 | +
|
| 85 | +检测到虚拟环境: .venv |
| 86 | +
|
| 87 | +当前 Python 环境: |
| 88 | +------------------------------------------ |
| 89 | +C:\Project\.venv\Scripts\python.exe |
| 90 | +Python 3.11.0 |
| 91 | +------------------------------------------ |
| 92 | +
|
| 93 | +========================================== |
| 94 | + 获取已安装包列表 |
| 95 | +========================================== |
| 96 | +
|
| 97 | +当前已安装的包: |
| 98 | +------------------------------------------ |
| 99 | +requests==2.31.0 |
| 100 | +numpy==1.24.0 |
| 101 | +------------------------------------------ |
| 102 | +
|
| 103 | +确认卸载以上所有包?(Y/N): Y |
| 104 | +
|
| 105 | +========================================== |
| 106 | + ✓ 环境重置完成! |
| 107 | +========================================== |
| 108 | +``` |
| 109 | + |
| 110 | +### 🤝 Contributing |
| 111 | + |
| 112 | +Contributions, issues, and feature requests are welcome! |
| 113 | + |
| 114 | +### 📄 License |
| 115 | + |
| 116 | +MIT License - feel free to use this tool in your projects. |
| 117 | + |
| 118 | +### 👤 Author |
| 119 | + |
| 120 | +Created with ❤️ for Python developers |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +<a name="chinese"></a> |
| 125 | +## 🌟 中文 |
| 126 | + |
| 127 | +### 项目简介 |
| 128 | + |
| 129 | +一个轻量级的 Windows 批处理脚本工具,用于安全地重置 Python 虚拟环境。它能自动检测并激活虚拟环境,卸载所有包,并重新安装必要的基础包。 |
| 130 | + |
| 131 | +### ✨ 功能特性 |
| 132 | + |
| 133 | +- 🔍 **自动检测**:自动检测常见的虚拟环境目录(`.venv`、`venv`、`env`、`.env`) |
| 134 | +- 🛡️ **安全优先**:在操作全局 Python 环境时会发出强烈警告 |
| 135 | +- 📦 **彻底清理**:卸载所有包并重新安装基础包(pip、setuptools、wheel) |
| 136 | +- 🎯 **用户友好**:在执行任何破坏性操作前都有清晰的提示和确认 |
| 137 | +- 🌐 **UTF-8 支持**:正确处理中文和其他 Unicode 字符 |
| 138 | + |
| 139 | +### 📋 系统要求 |
| 140 | + |
| 141 | +- Windows 操作系统 |
| 142 | +- 已安装 Python 3.x 并可通过 `python` 命令访问 |
| 143 | +- pip 包管理器 |
| 144 | + |
| 145 | +### 🚀 快速开始 |
| 146 | + |
| 147 | +1. **下载** `env-reset.bat` 文件 |
| 148 | +2. **放置** 到你的 Python 项目根目录(虚拟环境文件夹所在位置) |
| 149 | +3. **运行** 双击 `env-reset.bat` 或在命令提示符中执行 |
| 150 | + |
| 151 | +```batch |
| 152 | +env-reset.bat |
| 153 | +``` |
| 154 | + |
| 155 | +### 📖 使用方法 |
| 156 | + |
| 157 | +#### 虚拟环境模式(推荐) |
| 158 | + |
| 159 | +```bash |
| 160 | +# 首先创建虚拟环境(如果还没有) |
| 161 | +python -m venv .venv |
| 162 | + |
| 163 | +# 运行重置工具 |
| 164 | +env-reset.bat |
| 165 | +``` |
| 166 | + |
| 167 | +脚本将会: |
| 168 | +1. 检测并激活你的虚拟环境 |
| 169 | +2. 列出所有已安装的包 |
| 170 | +3. 请求确认 |
| 171 | +4. 卸载所有包 |
| 172 | +5. 升级 pip 并安装基础包 |
| 173 | + |
| 174 | +#### 全局环境模式(不推荐) |
| 175 | + |
| 176 | +如果未检测到虚拟环境,脚本将: |
| 177 | +1. 显示**强烈警告** |
| 178 | +2. 要求明确确认(输入大写的 `YES`) |
| 179 | +3. 仅在确认后才继续执行 |
| 180 | + |
| 181 | +### 🔧 支持的虚拟环境名称 |
| 182 | + |
| 183 | +- `.venv`(推荐) |
| 184 | +- `venv` |
| 185 | +- `env` |
| 186 | +- `.env` |
| 187 | + |
| 188 | +### ⚠️ 重要提示 |
| 189 | + |
| 190 | +- **始终使用虚拟环境**进行项目开发 |
| 191 | +- 脚本**不会**删除虚拟环境文件夹本身 |
| 192 | +- 基础包(pip、setuptools、wheel)会自动重新安装 |
| 193 | +- 如果存在 `requirements.txt`,会提醒你重新安装项目依赖 |
| 194 | + |
| 195 | +### 📝 输出示例 |
| 196 | + |
| 197 | +``` |
| 198 | +========================================== |
| 199 | + 虚拟环境重置工具 |
| 200 | +========================================== |
| 201 | +
|
| 202 | +检测到虚拟环境: .venv |
| 203 | +
|
| 204 | +当前 Python 环境: |
| 205 | +------------------------------------------ |
| 206 | +C:\Project\.venv\Scripts\python.exe |
| 207 | +Python 3.11.0 |
| 208 | +------------------------------------------ |
| 209 | +
|
| 210 | +========================================== |
| 211 | + 获取已安装包列表 |
| 212 | +========================================== |
| 213 | +
|
| 214 | +当前已安装的包: |
| 215 | +------------------------------------------ |
| 216 | +requests==2.31.0 |
| 217 | +numpy==1.24.0 |
| 218 | +------------------------------------------ |
| 219 | +
|
| 220 | +确认卸载以上所有包?(Y/N): Y |
| 221 | +
|
| 222 | +========================================== |
| 223 | + ✓ 环境重置完成! |
| 224 | +========================================== |
| 225 | +``` |
| 226 | + |
| 227 | +### 🤝 贡献 |
| 228 | + |
| 229 | +欢迎贡献代码、提出问题和功能请求! |
| 230 | + |
| 231 | +### 📄 许可证 |
| 232 | + |
| 233 | +MIT 许可证 - 可自由在你的项目中使用此工具。 |
| 234 | + |
| 235 | +### 👤 作者 |
| 236 | + |
| 237 | +用 ❤️ 为 Python 开发者创建 |
| 238 | + |
| 239 | +--- |
| 240 | + |
| 241 | +## 🌐 Links |
| 242 | + |
| 243 | +- [Report Bug](../../issues) |
| 244 | +- [Request Feature](../../issues) |
| 245 | + |
| 246 | +## ⭐ Star History |
| 247 | + |
| 248 | +If you find this tool helpful, please consider giving it a star! |
0 commit comments