简体   繁体   English

在 macOS Sierra 中,如何配置 AWS CLI 以使用 Python3.x 而不是操作系统默认的 Python2.7?

[英]In macOS Sierra, How Configure AWS CLI to Use Python3.x Instead of the OS Default Python2.7?

AWS CLI Mavens, AWS CLI Mavens,

Via macOS' Terminal, trying to install and configure AWS CLI on macOS Sierra 10.12.6 to use Python 3.6.2 instead of macOS' default, Python 2.7.10.通过 macOS 的终端,尝试在 macOS Sierra 10.12.6 上安装和配置AWS CLI以使用Python 3.6.2而不是macOS 的默认 Python 2.7.10。

Although I rigorously followed AWS' instructions ( http://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-install-macos.html ), including configuring ./bash_profile thus:尽管我严格遵循 AWS 的说明( http://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-install-macos.html ),包括配置 ./bash_profile :

# Setting PATH for Python 3.6.x
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

and double-checking via **echo $PATH**并通过**echo $PATH**检查

PATH=/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

When executing执行时

$ aws --version

the result is always this:结果总是这样:

aws-cli/1.10.60 Python/2.7.10 Darwin/16.7.0 botocore/1.4.50

Thank you in advance for any suggestions as to how to configure AWS CLI to ignore Python 2.7.10 and execute via Python 3.6.x.预先感谢您提供有关如何配置 AWS CLI 以忽略 Python 2.7.10 并通过 Python 3.6.x 执行的任何建议。

Plane Wryter飞机打字机

In my case, I solved this problem via followings.就我而言,我通过以下方式解决了这个问题。

$ pip3 --version
  pip 18.1 from {....} (python 3.6)
$ export PATH=~/.local/bin:~/Library/Python/3.6/bin:$PATH 
$ pip3 install awscli --upgrade  # without --user
$ aws --version
  aws-cli/1.16.22 Python/3.6.5 Darwin/18.2.0 botocore/1.12.12

It sounds like you may have the awscli installed twice under different versions of Python, and the version installed on System Python is taking precedence.听起来您可能在不同版本的 Python 下安装了两次awscli ,并且安装在 System Python 上的版本优先。

Try running both of these commands and see if it shows up in both:尝试运行这两个命令,看看它是否出现在两个命令中:

$ pip3 freeze | grep awscli

Then:然后:

$ pip2 freeze | grep awscli

If it's listed in the latter, then run:如果它列在后者中,则运行:

$ pip2 uninstall awscli

With a fresh install today, this is the output I get:今天进行全新安装,这是我得到的输出:

$ aws --version
aws-cli/1.11.162 Python/3.6.2 Darwin/15.6.0 botocore/1.7.20

I'm not very familiar with how AWS recommends installing Python on macOS, but the most flexible way in my opinion is to install pyenv via brew then manage your Python versions through pyenv.我不太熟悉 AWS 建议如何在 macOS 上安装 Python,但我认为最灵活的方法是通过brew安装pyenv ,然后通过 pyenv 管理您的 Python 版本。 This allows you the flexibility of having multiple subversions of Python 2 and Python 3 installed simultaneously, as well as System Python.这使您可以灵活地同时安装 Python 2 和 Python 3 的多个子版本以及系统 Python。 I would recommend this approach here as well.我也会在这里推荐这种方法。

How did you install awscli ?你是如何安装awscli Did you use pip that comes with Python 3?你用过 Python 3 自带的 pip 吗?

Check which pip you're using and use the one for Python 3 to install awscli.检查您使用的是哪个 pip,并使用 Python 3 的那个来安装 awscli。

I was able to get it work by doing this我能够通过这样做来让它工作

export PATH=~/.local/bin:~/Library/Python/3.6/bin:$PATH 
pip3 install awscli

I faced the same issue.我遇到了同样的问题。 Instead of fixing it, I altered my path and installed with brew.我没有修复它,而是改变了我的路径并安装了 brew。 It was seamless and the fastest solution.这是无缝且最快的解决方案。

$brew install awscli

Then,然后,

$aws --version

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM