【问题标题】:Why does installing boto3 break my installation of awscli?为什么安装 boto3 会破坏我的 awscli 安装?
【发布时间】:2018-09-20 21:04:14
【问题描述】:

我正在尝试安装 boto3,以便可以在我想要在运行 Ubuntu 14.04 的 EC2 实例上运行的 python 脚本中使用它。无论如何,我安装 boto3 它会破坏我在非 root 用户上安装 awscli。我使用带有sudo apt-get install awscli 的apt get 安装awscli。安装后,root用户和ubuntu用户都可以使用。

ubuntu@ip-10-12-10-8:~$ aws --version
aws-cli/1.14.65 Python/2.7.6 Linux/3.13.0-143-generic botocore/1.9.18
ubuntu@ip-10-12-10-8:~$ sudo aws --version
aws-cli/1.14.65 Python/2.7.6 Linux/3.13.0-143-generic botocore/1.9.18

我也尝试过安装 AWS 建议的 sudo pip install awscli --upgrade --user 的 awscli。此外,如果这意味着任何 pip 仅以 root 用户身份运行,则可能安装错误。

这是我用 pip 安装 boto3 时的输出。

但是,每当我使用 pip 安装 boto3 时,它都会对 ubuntu 用户造成破坏。我尝试安装 boto3,然后以多种不同的方式安装 awscli,但没有任何效果。以下是我尝试过的方法。

ubuntu@ip-10-12-10-8:~$ sudo pip install boto3
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting boto3
/usr/local/lib/python2.7/dist-packages/pip/_vendor/urllib3/util/ssl_.py:339: 
SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/urllib3/util/ssl_.py:137: 
  InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecurePlatformWarning
  Downloading boto3-1.7.4-py2.py3-none-any.whl (128kB)
    100% |████████████████████████████████| 133kB 6.9MB/s 
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in 
/usr/local/lib/python2.7/dist-packages (from boto3)
Requirement already satisfied: s3transfer<0.2.0,>=0.1.10 in 
/usr/local/lib/python2.7/dist-packages (from boto3)
Collecting botocore<1.11.0,>=1.10.4 (from boto3)
  Downloading botocore-1.10.4-py2.py3-none-any.whl (4.2MB)
    100% |████████████████████████████████| 4.2MB 328kB/s 
Requirement already satisfied: futures<4.0.0,>=2.2.0; python_version == "2.6" or python_version == "2.7" in /usr/local/lib/python2.7/dist-packages (from s3transfer<0.2.0,>=0.1.10->boto3)
Requirement already satisfied: python-dateutil<2.7.0,>=2.1 in 
/usr/local/lib/python2.7/dist-packages (from botocore<1.11.0,>=1.10.4->boto3)
Requirement already satisfied: docutils>=0.10 in /usr/local/lib/python2.7/dist-packages (from botocore<1.11.0,>=1.10.4->boto3)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python2.7/dist-packages (from python-dateutil<2.7.0,>=2.1->botocore<1.11.0,>=1.10.4->boto3)
Installing collected packages: botocore, boto3
  Found existing installation: botocore 1.9.18
    Uninstalling botocore-1.9.18:
      Successfully uninstalled botocore-1.9.18
Successfully installed boto3-1.7.4 botocore-1.10.4

然后这就是结果。我需要 aws 工具来像安装 boto3 之前那样对两个用户都工作。

ubuntu@ip-10-12-10-8:~$ aws --version
Traceback (most recent call last):
  File "/usr/local/bin/aws", line 19, in <module>
    import awscli.clidriver
  File "/usr/local/lib/python2.7/dist-packages/awscli/clidriver.py", line 17, in <module>
    import botocore.session
ImportError: No module named botocore.session
ubuntu@ip-10-12-10-8:~$ sudo aws --version
aws-cli/1.14.65 Python/2.7.6 Linux/3.13.0-143-generic botocore/1.10.

发生了什么事?我一直在这。

【问题讨论】:

  • 如果再次安装 awscli 会怎样?
  • 还是不行。给出同样的错误。
  • 试试这个:sudo pip install awscli --force-reinstall --upgrade
  • 我已经从另一个 SO 帖子中尝试过这个命令。这导致 aws 也只能在 sudo 用户上工作。
  • sudo -H pip 怎么样。它为所有用户安装。

标签: python ubuntu pip boto3


【解决方案1】:

这是我使用的,它还会安装 awscli 和具有自动完成功能的 aws-shell。

$ sudo pip install aws-shell --upgrade --ignore-installed six

如果这修复了 boto3 和 awscli,请告诉我。

【讨论】:

  • 适用于 Ubuntu 20.04,谢谢!
【解决方案2】:

awscli 维护者的回应是“不要使用除pip 之外的任何东西来安装awscli”。 https://github.com/aws/aws-cli/issues/2353#issuecomment-270492205

每个 cmets 将 sudo 用于 pip install。这会起作用,但正如提到的sudo -H pip install somepackage 或者更好的sudo -H -E pip install somepackage 应该安装它并且在系统范围内可用。另一种选择是培训您的用户使用pip install --user awscli,以便只有需要运行它的用户才能使用它,并且恶意脚本/用户无法使用实例的 IAM 角色访问内容。

如果它仍然无法使用上述内容,则可能是这个极端情况错误,如果 /tmp 使用 noexec 安装,则安装后不会正确地使用 +x 权限标记 aws 二进制文件。您可以尝试运行python3 /usr/bin/awspython /usr/bin/aws(它也可能在/usr/local/bin/aws 中),看看是否返回aws 命令的预期输出。

另一个答案中提到的另一种选择是将其安装到虚拟环境中,这是一种很好的隔离事物的方法,但如果您不具备正确的权限使其在系统范围内可用,则可能会很棘手。不熟悉虚拟环境。

【讨论】:

    【解决方案3】:

    如果您从不使用virtualenv,请立即使用。

    或者您可以使用conda,这是另一个python 虚拟环境。

    它将解决您的“问题”。

    这是一个设计上的“问题”。尽管如此,即使不使用 AWSCLI,也必须始终学习为他们的 python 应用程序设置 python virtualenv,即使只有一个项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-21
      • 1970-01-01
      • 2021-12-12
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      相关资源
      最近更新 更多