简体   繁体   中英

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

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.

Although I rigorously followed AWS' instructions ( http://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-install-macos.html ), including configuring ./bash_profile thus:

# 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**

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.

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.

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. This allows you the flexibility of having multiple subversions of Python 2 and Python 3 installed simultaneously, as well as System Python. I would recommend this approach here as well.

How did you install awscli ? Did you use pip that comes with Python 3?

Check which pip you're using and use the one for Python 3 to install 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. It was seamless and the fastest solution.

$brew install awscli

Then,

$aws --version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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