# ImportError：pip install --target ./lib requests 后找不到名为 'requests' 的模块

- **ID:** `python/pip-target-not-in-path`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pip install --target 将包安装到指定目录，但不会将其添加到 sys.path。除非更新 PYTHONPATH 或 sys.path，否则解释器找不到该包。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   export PYTHONPATH=$PWD/lib:$PYTHONPATH && python -c 'import requests'
   ```
2. **** (90% 成功率)
   ```
   import sys, os; sys.path.insert(0, os.path.abspath('./lib')); import requests
   ```
3. **** (85% 成功率)
   ```
   echo $(pwd)/lib > $(python -c 'import site; print(site.getsitepackages()[0])')/mylib.pth
   ```

## 无效尝试

- **** — Reinstalling does not change sys.path. (95% 失败率)
- **** — pip still installs to the active environment's site-packages, not the cwd. (90% 失败率)
