Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 209
Plane Wryter Avatar asked Sep 23 '17 01:09

Plane Wryter


2 Answers

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
like image 91
hojin Avatar answered Sep 23 '22 14:09

hojin


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.

like image 24
Taylor D. Edmiston Avatar answered Sep 23 '22 14:09

Taylor D. Edmiston