> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 添加 Python 库

Agno 模板使用 `pyproject.toml` 文件来管理依赖项，**该文件用于通过 [uv](https://github.com/astral-sh/uv) 或 [pip-tools](https://pip-tools.readthedocs.io/en/latest/) 生成 `requirements.txt` 文件。**

添加或更新 Python 库是一个包含两个步骤的过程：

1. 将库添加到 `pyproject.toml` 文件
2. 自动生成 `requirements.txt` 文件

<Warning>
  我们强烈建议通过此过程自动生成 `requirements.txt` 文件。
</Warning>

## 更新 pyproject.toml

* 打开 `pyproject.toml` 文件
* 在 dependencies 部分添加新库。

## 生成 requirements

在更新 `pyproject.toml` 文件中的 `dependencies` 后，使用辅助脚本或直接运行 `pip-compile` 来自动生成 `requirements.txt` 文件。

<CodeGroup>
  ```bash terminal theme={null}
  ./scripts/generate_requirements.sh
  ```

  ```bash pip compile theme={null}
  pip-compile \
      --no-annotate \
      --pip-args "--no-cache-dir" \
      -o requirements.txt pyproject.toml
  ```
</CodeGroup>

如果您想将所有 Python 库升级到最新版本，请运行：

<CodeGroup>
  ```bash terminal theme={null}
  ./scripts/generate_requirements.sh upgrade
  ```

  ```bash pip compile theme={null}
  pip-compile \
      --upgrade \
      --no-annotate \
      --pip-args "--no-cache-dir" \
      -o requirements.txt pyproject.toml
  ```
</CodeGroup>

## 重建镜像

更新 `requirements.txt` 文件后，重建您的镜像。

### 重建开发镜像

<CodeGroup>
  ```bash terminal theme={null}
  ag ws up --env dev --infra docker --type image
  ```

  ```bash short options theme={null}
  ag ws up -e dev -i docker -t image
  ```
</CodeGroup>

### 重建生产镜像

<Note>
  如果需要，请记住[使用 ECR 进行身份验证](workspaces/workspace-management/production-app#ecr-images)。
</Note>

<CodeGroup>
  ```bash terminal theme={null}
  ag ws up --env prd --infra aws --type image
  ```

  ```bash short options theme={null}
  ag ws up -e prd -i aws -t image
  ```
</CodeGroup>

## 重新创建资源

重建镜像后，重新创建资源。

### 重新创建开发容器

<CodeGroup>
  ```bash terminal theme={null}
  ag ws restart --env dev --infra docker --type container
  ```

  ```bash short options theme={null}
  ag ws restart -e dev -c docker -t container
  ```
</CodeGroup>

### 更新 ECS 服务

<CodeGroup>
  ```bash terminal theme={null}
  ag ws patch --env prd --infra aws --name service
  ```

  ```bash short options theme={null}
  ag ws patch -e prd -i aws -n service
  ```
</CodeGroup>
