# 错误：无法打开需求文件：[Errno 2] 没有那个文件或目录：'requirements\.txt'

- **ID:** `pip/requirements-file-encoding-issue`
- **领域:** pip
- **类别:** config_error
- **错误码:** `ERROR`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

需求文件路径包含由于 shell 转义或文件系统编码不匹配而被误解的 Unicode 字符（例如文件名中的不间断空格或从右到左标记），导致实际文件路径与指定路径不同。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| pip 23.3 | active | — | — |
| pip 24.0 | active | — | — |
| pip 24.2 | active | — | — |

## 解决方案

1. ```
   使用 Tab 补全从文件系统中选择精确的文件名：pip install -r ./req<tab>
   ```
2. ```
   使用 ls -b 列出目录以查看转义字符，并用干净名称重新创建文件：ls -b | grep requirements && cp "$(ls | grep requirements)" requirements_clean.txt
   ```
3. ```
   使用能显示不可见字符的文本编辑器（例如带 :set list 的 vim）从头重新创建需求文件。
   ```

## 无效尝试

- **Use a different shell (e.g., bash instead of zsh) to run the pip command** — The issue is not shell-specific; the filename on disk contains an invisible Unicode character that persists across shells. (95% 失败率)
- **Rename the file using mv requirements.txt requirements_fixed.txt** — If the filename contains invisible characters, typing 'requirements.txt' in the mv command may also include those characters, resulting in the same filename or a different one. (70% 失败率)
