# ModuleNotFoundError: 没有名为 'starlette' 的模块

- **ID:** `python/starlette-import-error-no-module-named-starlette`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

当前 Python 环境中未安装 Starlette。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Install Starlette using pip.** (95% 成功率)
   ```
   pip install starlette
   ```
2. **Install FastAPI which includes Starlette.** (90% 成功率)
   ```
   pip install fastapi
   ```

## 无效尝试

- **Installing starlette with pip but using a virtual environment not activated.** — If the virtual environment is not activated, the package is installed in the system Python, not the project's environment. (80% 失败率)
- **Assuming starlette is included with FastAPI.** — FastAPI depends on Starlette, but if you install only FastAPI, Starlette is installed as a dependency. However, if you uninstall FastAPI, Starlette may also be removed. (60% 失败率)
