24

When trying to run the AWS CLI, I am getting this error:

aws
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha512
Traceback (most recent call last):
  File "/usr/local/bin/aws", line 19, in <module>
    import awscli.clidriver
  File "/usr/local/lib/python2.7/site-packages/awscli/clidriver.py", line 17, in <module>
    import botocore.session
  File "/usr/local/lib/python2.7/site-packages/botocore/session.py", line 29, in <module>
    import botocore.configloader
  File "/usr/local/lib/python2.7/site-packages/botocore/configloader.py", line 19, in <module>
    from botocore.compat import six
  File "/usr/local/lib/python2.7/site-packages/botocore/compat.py", line 25, in <module>
    from botocore.exceptions import MD5UnavailableError
  File "/usr/local/lib/python2.7/site-packages/botocore/exceptions.py", line 15, in <module>
    from botocore.vendored import requests
  File "/usr/local/lib/python2.7/site-packages/botocore/vendored/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/usr/local/lib/python2.7/site-packages/botocore/vendored/requests/utils.py", line 26, in <module>
    from .compat import parse_http_list as _parse_list_header
  File "/usr/local/lib/python2.7/site-packages/botocore/vendored/requests/compat.py", line 7, in <module>
    from .packages import chardet
  File "/usr/local/lib/python2.7/site-packages/botocore/vendored/requests/packages/__init__.py", line 3, in <module>
    from . import urllib3
  File "/usr/local/lib/python2.7/site-packages/botocore/vendored/requests/packages/urllib3/__init__.py", line 10, in <module>
    from .connectionpool import (
  File "/usr/local/lib/python2.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 31, in <module>
    from .connection import (
  File "/usr/local/lib/python2.7/site-packages/botocore/vendored/requests/packages/urllib3/connection.py", line 45, in <module>
    from .util.ssl_ import (
  File "/usr/local/lib/python2.7/site-packages/botocore/vendored/requests/packages/urllib3/util/__init__.py", line 5, in <module>
    from .ssl_ import (
  File "/usr/local/lib/python2.7/site-packages/botocore/vendored/requests/packages/urllib3/util/ssl_.py", line 2, in <module>
    from hashlib import md5, sha1, sha256
ImportError: cannot import name md5

I tried the solution from this issue but they do not work:

brew reinstall python@2
==> Reinstalling python@2
Error: An exception occurred within a child process:
  FormulaUnavailableError: No available formula with the name "/usr/local/opt/python@2/.brew/python@2.rb"

I thought it might not be installed, but it already is:

brew install python@2
Warning: python@2 2.7.15_1 is already installed and up-to-date
To reinstall 2.7.15_1, run `brew reinstall python@2`

Running brew doctor shows that python is unliked, but running brew link python fails because of a symlink belonging to python@2.

brew link python
Linking /usr/local/Cellar/python/3.7.6_1...
Error: Could not symlink Frameworks/Python.framework/Headers
Target /usr/local/Frameworks/Python.framework/Headers
is a symlink belonging to python@2. You can unlink it:
  brew unlink python@2

To force the link and overwrite all conflicting files:
  brew link --overwrite python

To list all files that would be deleted:
  brew link --overwrite --dry-run python

The commands recommended seem to go in circle and none of them manage to solve the issue. I am a bit stuck - how do I recover from these errors?

Pauline
  • 3,566
  • 8
  • 23
  • 39
  • I recommend you to purge that version from your system, and download the new AWS CLI v2, which is provided by a bundled package to prevent such dependencies with Python –  Feb 14 '20 at 16:20
  • @eez0 I can try, but I am running in the same issue:```pip uninstall awscli``` ```ERROR:root:code for hash md5 was not found.``` – Pauline Feb 14 '20 at 16:31
  • 1
    Try ```brew reinstall awscli``` – Doyin Olarewaju Feb 22 '20 at 11:02

3 Answers3

56

Ran into a similar issue with brew install python2 error when trying to use pip.

It's probably because

python@2 was deleted from homebrew/core in commit 028f11f9e:
python@2: delete (https://github.com/Homebrew/homebrew-core/issues/49796)
EOL 1 January 2020.

See this post here https://github.com/Homebrew/homebrew-core/pull/49796 for more details.

To fix this,

  1. run brew uninstall python@2 to uninstall brew installed python@2 this should make default python2 fall back to python2 came with macOS.
  2. uninstall current aws cli by running

    • sudo rm -rf /usr/local/bin/aws
    • sudo rm -rf /usr/local/aws
    • rm AWSCLIV2.pkg
  3. install aws cli again by running

    • sudo curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
    • sudo installer -pkg AWSCLIV2.pkg -target /
  4. if you run aws --version you should see it's linked to python3 instead of python2.

Hope it helps.

Gary Bao 鲍昱彤
  • 2,608
  • 20
  • 31
  • Mojave 10.14 - after brew uninstall python@2 - aws cli it gets linked to python3 with no issue. – Sgryt Jun 18 '20 at 02:08
  • I got an `curl` error with `3.`, it's easier to install AWS CLI by following their instruction at https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html – Tien Do Dec 18 '20 at 03:40
  • this created so many problems for me...ah should have known this is what 2020 was going to be like – user3768258 Dec 30 '20 at 08:39
1

I had the same problem after running brew install imagemagick.

Both autojump and awscli gave me above error.

The issue is caused by a conflict between openssl that is installed by homebrew and the macOS SSL lib? See here and here

Running the commands below fixed it for me

brew reinstall python@2
brew reinstall awscli
mozey
  • 2,222
  • 2
  • 27
  • 34
0

I have the same error running awscli after brew installed gimme-aws-creds, which installed python@3.8. So in my case, I now have both python@2 and python3.8, and awscli is still linked to python@2, instead of the new phyhon@3.8.

When reinstalling awscli, the error message clearly indicates a conflicting file,

$ brew reinstall awscli ... ==> Reinstalling awscli
Error: The brew link step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink bin/aws Target /usr/local/bin/aws already exists. > You may want to remove it: rm '/usr/local/bin/aws'

Simply removing the conflicting file, /usr/local/bin/aws resolved the issue.

BJYC
  • 354
  • 2
  • 10