Python 为什么安装boto3会破坏我的awscli安装?

Python 为什么安装boto3会破坏我的awscli安装?,python,ubuntu,pip,boto3,Python,Ubuntu,Pip,Boto3,我正在尝试安装boto3,这样我就可以在python脚本中使用它,我想在运行Ubuntu14.04的EC2实例上运行它。无论如何,我安装了bot3,它破坏了我在非root用户上安装的awscli。我使用apt get withsudo apt get install awscli安装awscli。安装后,它可以在root用户和ubuntu用户上运行 ubuntu@ip-10-12-10-8:~$ aws --version aws-cli/1.14.65 Python/2.7.6 Linux/3

我正在尝试安装boto3,这样我就可以在python脚本中使用它,我想在运行Ubuntu14.04的EC2实例上运行它。无论如何,我安装了bot3,它破坏了我在非root用户上安装的awscli。我使用apt get with
sudo apt get install awscli
安装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建议的那样安装awscli,使用
sudopip安装awscli--upgrade--user
。另外,如果它意味着pip只作为根用户运行,那么可能是安装错误了

这是我用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
ubuntu@ip-10-12-10-8:~$sudo pip安装boto3
当前用户不拥有目录“/home/ubuntu/.cache/pip/http”或其父目录,缓存已被禁用。请检查该目录的权限和所有者。如果使用sudo执行pip,您可能需要sudo的-H标志。
当前用户不拥有目录“/home/ubuntu/.cache/pip”或其父目录,并且已禁用缓存控制盘。检查该目录的权限和所有者。如果使用sudo执行pip,您可能需要sudo的-H标志。
收集boto3
/usr/local/lib/python2.7/dist-packages/pip/_-vendor/urllib3/util/ssl.py:339:
SNIMissingWarning:已发出HTTPS请求,但TLS的SNI(主题名称指示)扩展在此平台上不可用。这可能会导致服务器提供不正确的TLS证书,从而导致验证失败。您可以升级到较新版本的Python来解决此问题。有关详细信息,请参阅https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-警告
SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_-vendor/urllib3/util/ssl.py:137:
不安全平台警告:真正的SSLContext对象不可用。这会阻止urllib3正确配置SSL,并可能导致某些SSL连接失败。您可以升级到较新版本的Python来解决此问题。有关详细信息,请参阅https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-警告
不安全平台警告
下载boto3-1.7.4-py2.py3-none-any.whl(128kB)
100% |████████████████████████████████| 133kB 6.9MB/s
已满足要求:jmespath=0.7.1英寸
/usr/local/lib/python2.7/dist-packages(来自boto3)
已满足要求:s3transfer=0.1.10英寸
/usr/local/lib/python2.7/dist-packages(来自boto3)
收集botocore=1.10.4(来自boto3)
下载botocore-1.10.4-py2.py3-none-any.whl(4.2MB)
100% |████████████████████████████████| 4.2MB 328kB/s
已满足的要求:期货=2.2.0;/usr/local/lib/python2.7/dist-packages中的python_version==“2.6”或python_version==“2.7”(来自s3transfer=0.1.10->boto3)
已满足要求:python dateutil=2.1 in
/usr/local/lib/python2.7/dist-packages(来自botocore=1.10.4->boto3)
已满足要求:docutils>=0.10 in/usr/local/lib/python2.7/dist-packages(来自botocore=1.10.4->boto3)
已满足要求:六个>=1.5 in/usr/local/lib/python2.7/dist-packages(来自python-dateutil=2.1->botocore=1.10.4->boto3)
安装收集的软件包:botocore、boto3
找到现有安装:botocore 1.9.18
卸载botocore-1.9.18:
已成功卸载botocore-1.9.18
已成功安装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.
ubuntu@ip-10-12-10-8:~$aws--版本
回溯(最近一次呼叫最后一次):
文件“/usr/local/bin/aws”,第19行,在
导入awscli.clidriver
文件“/usr/local/lib/python2.7/dist-packages/awscli/clidriver.py”,第17行,在
导入botocore.session
ImportError:没有名为botocore.session的模块
ubuntu@ip-10-12-10-8:~$sudo aws--版本
aws cli/1.14.65 Python/2.7.6 Linux/3.13.0-143-generic botocore/1.10。

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

这就是我使用的,它还将安装awscli和aws外壳,它有自动完成功能等等

$ sudo pip install aws-shell --upgrade --ignore-installed six
如果这可以修复O3和awscli,请告诉我。

如果您从未使用过,请立即使用

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

它会解决你的“问题”


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

来自
awscli
维护人员的响应是“除了
pip
之外,不要使用任何东西来安装
awscli

每两条注释使用
sudo
进行
pip安装
。这将起作用,但正如前面提到的那样,sudo-H-pip install somepackage或者更好的
sudo-H-E-pip install somepackage
应该能够在系统范围内安装并可用。另一个选项是训练用户使用
pip安装--user awscli
,这样只有那些需要运行它的用户才能使用它,恶意脚本/用户不能使用实例的IAM角色访问内容

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

中提到的另一种选择