'AWS throws the following error: "bad interpreter: No such file or directory"

I'm not aware of anything on my system having changed, but the aws CLI tool has stopped working.

$ aws-bash: /Users/user_name/Library/Python/3.7/bin/aws:/usr/local/opt/python/bin/
python3.7: bad interpreter: No such file or directory

I've tried brew reinstall awscli which is suggested elsewhere, but with no luck.



Solution 1:[1]

Another option would be to look into .bash_profile or .zshrc, look for line that looks like this:

export PATH=/Users/user_name/Library/Python/3.7/bin/:$PATH

Try commenting it first. If it works for you - remove it.

What this line does is prepending the lookup path for binaries, which in turn takes priority over brew installation.

Solution 2:[2]

Another solution

# Reinstall awscli using your latest/current Python installation
brew reinstall awscli

# Overwrite the existing /usr/local/bin/aws with the new installation
brew link --overwrite awscli

Solution 3:[3]

I solved this issue by reviewing my .bash_profile. There was an old entry which got invalid after updating python.

Just for the case someone also forgot to look the obvious first, like me... ;)

Solution 4:[4]

You probably don't need to reinstall awscli, but just update its Python path.

Check which Python versions are installed:

ls /usr/bin/python*
# /usr/bin/python2    /usr/bin/python3    /usr/bin/python2.7  /usr/bin/python3.6

python3 -V
# Python 3.6.8

Locate aws command, and update its python path:

which aws
# ~/.local/bin/aws

vi ~/.local/bin/aws
#!/usr/bin/python3

Try to call aws again:

$ aws
# usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Kaka Ruto
Solution 3 Pateta
Solution 4 Noam Manos