

**本文档仅适用于 AWS CLI 版本 1。**

我们已宣布即将终止对 AWS CLI 版本 1 的支持。建议您迁移到 AWS CLI 版本 2。有关日期、其它详细信息以及如何迁移的信息，请参阅[公告](https://aws.amazon.com/blogs/developer/cli-v1-maintenance-mode-announcement/)。有关 AWS CLI 版本 2 的相关文档，请参阅[版本 2 用户指南](https://docs.aws.amazon.com/cli/latest/userguide/)。

# 在虚拟环境中安装和更新 AWS CLI 版本 1
<a name="install-virtualenv"></a>

您可以通过在虚拟环境中安装 AWS Command Line Interface (AWS CLI) 的版本 1，避免与其他 `pip` 程序包之间的版本要求冲突。

**Topics**
+ [先决条件](#install-virtualenv-prereqs)
+ [在虚拟环境中安装和更新 AWS CLI 版本 1](#install-virtualenv-install)
+ [AWS CLI 安装和卸载错误故障排除](#install-virtualenv-tshoot)

## 先决条件
<a name="install-virtualenv-prereqs"></a>
+ Python 3.8 或更高版本。有关安装说明，请参阅 Python 的*初学者指南* 中的[下载 Python](https://wiki.python.org/moin/BeginnersGuide/Download) 页面。

  **Python 版本支持矩阵**    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/cli/v1/userguide/install-virtualenv.html)
+ `pip` 或 `pip3` 已安装。

## 在虚拟环境中安装和更新 AWS CLI 版本 1
<a name="install-virtualenv-install"></a>

1. 使用 `virtualenv` 安装 `pip`。

   ```
   $ pip install --user virtualenv
   ```

1. 创建虚拟环境并命名它。

   ```
   $ virtualenv ~/cli-ve
   ```

   或者，您也可以使用 `-p` 选项指定默认版本以外的 Python 版本。

   ```
   $ virtualenv -p /usr/bin/python37 ~/cli-ve
   ```

1. 激活新虚拟环境。

   **Linux 或 macOS**

   ```
   $ source ~/cli-ve/bin/activate
   ```

   **Windows**

   ```
   $ %USERPROFILE%\cli-ve\Scripts\activate
   ```

   提示符更改为显示您的虚拟环境处于活动状态。

   ```
   (cli-ve)~$
   ```

1. 将 AWS CLI 版本 1 安装到您的虚拟环境中或进行更新。

   ```
   (cli-ve)~$ pip install --upgrade awscli
   ```

1. 验证 AWS CLI 版本 1 是否已正确安装。

   ```
   $ aws --version
   aws-cli/1.40.41 Python/3.11.6 Linux/5.10.205-195.807.amzn2.x86_64 botocore/1.18.6
   ```

1. 您可以使用 `deactivate` 命令退出虚拟环境。不管何时启动新会话，都必须重新激活环境。

## AWS CLI 安装和卸载错误故障排除
<a name="install-virtualenv-tshoot"></a>

如果您在安装或卸载 AWS CLI 后遇到问题，请参阅[排查 AWS CLI 错误](cli-chap-troubleshooting.md)以了解故障排除步骤。有关相关性最高的故障排除步骤，请参阅[找不到命令错误](cli-chap-troubleshooting.md#tshoot-install-not-found)、[“`aws --version`”命令返回的版本与您安装的版本不同](cli-chap-troubleshooting.md#tshoot-install-wrong-version)和[卸载 AWS CLI 后，“`aws --version`”命令返回一个版本](cli-chap-troubleshooting.md#tshoot-uninstall-1)。