ERROR
pip
config_error
ai_generated
true
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements\.txt'
ID: pip/requirements-file-encoding-issue
90%Fix Rate
80%Confidence
1Evidence
2024-02-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| pip 23.3 | active | — | — | — |
| pip 24.0 | active | — | — | — |
| pip 24.2 | active | — | — | — |
Root Cause
The requirements file path contains a Unicode character that is misinterpreted due to shell escaping or file system encoding mismatch (e.g., a non-breaking space or right-to-left mark in the filename), causing the actual file path to differ from the specified one.
generic中文
需求文件路径包含由于 shell 转义或文件系统编码不匹配而被误解的 Unicode 字符(例如文件名中的不间断空格或从右到左标记),导致实际文件路径与指定路径不同。
Official Documentation
https://pip.pypa.io/en/stable/user_guide/#requirements-filesWorkarounds
-
90% success Use tab completion to select the exact filename from the filesystem: pip install -r ./req<tab>
Use tab completion to select the exact filename from the filesystem: pip install -r ./req<tab>
-
85% success List the directory with ls -b to see escaped characters and recreate the file with a clean name: ls -b | grep requirements && cp "$(ls | grep requirements)" requirements_clean.txt
List the directory with ls -b to see escaped characters and recreate the file with a clean name: ls -b | grep requirements && cp "$(ls | grep requirements)" requirements_clean.txt
-
95% success Recreate the requirements file from scratch using a text editor that shows invisible characters (e.g., vim with :set list).
Recreate the requirements file from scratch using a text editor that shows invisible characters (e.g., vim with :set list).
中文步骤
使用 Tab 补全从文件系统中选择精确的文件名:pip install -r ./req<tab>
使用 ls -b 列出目录以查看转义字符,并用干净名称重新创建文件:ls -b | grep requirements && cp "$(ls | grep requirements)" requirements_clean.txt
使用能显示不可见字符的文本编辑器(例如带 :set list 的 vim)从头重新创建需求文件。
Dead Ends
Common approaches that don't work:
-
Use a different shell (e.g., bash instead of zsh) to run the pip command
95% fail
The issue is not shell-specific; the filename on disk contains an invisible Unicode character that persists across shells.
-
Rename the file using mv requirements.txt requirements_fixed.txt
70% fail
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.