3

running MacOs v10.15.v and AWS CLI with Python v.3.7.2 and it yields with error -

qwerty@qwerty-mbp > aws --version
Traceback (most recent call last):
  File "/usr/local/bin/aws", line 19, in <module>
    import awscli.clidriver
  File "/usr/local/aws/lib/python3.7/site-packages/awscli/clidriver.py", line 17, in <module>
    import botocore.session
  File "/usr/local/aws/lib/python3.7/site-packages/botocore/session.py", line 30, in <module>
    import botocore.credentials
  File "/usr/local/aws/lib/python3.7/site-packages/botocore/credentials.py", line 42, in <module>
    from botocore.utils import InstanceMetadataFetcher, parse_key_val_file
  File "/usr/local/aws/lib/python3.7/site-packages/botocore/utils.py", line 31, in <module>
    import botocore.httpsession
  File "/usr/local/aws/lib/python3.7/site-packages/botocore/httpsession.py", line 7, in <module>
    from urllib3.util.ssl_ import (
ImportError: cannot import name 'ssl' from 'urllib3.util.ssl_' (/usr/local/aws/lib/python3.7/site-packages/urllib3/util/ssl_.py)

Any pointer would be much appreciated!

Theo Sweeny
  • 1,033
  • 14
  • 26

2 Answers2

2

I had the same problem. You can verify ssl module is not installed in the python distribution :

 /usr/local/Cellar/python@3.8/3.8.3_2/bin/python3
Python 3.8.3 (default, Jul 10 2020, 18:24:31)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python@3.8/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
>>>

Instead of installing a python bundle outside of brew and installing aws command line outside of brew as described in the self-answer to this question, here is the solution that worked for me

  • install Xcode tools : xcode-select --install
  • reinstall python's version of brew : brew reinstall python@3.8

After that

/usr/local/Cellar/python@3.8/3.8.3_2/bin/python3
Python 3.8.3 (default, Jul  8 2020, 14:27:55)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>
aws --version
aws-cli/2.0.30 Python/3.8.3 Darwin/19.5.0 botocore/2.0.0dev34
Sébastien Stormacq
  • 14,301
  • 5
  • 41
  • 64
-1

Okay - so I found an article on this site which goes over the uninstall process for Python and how to get a clean slate back, on which to work from seen here.

The key parts from which I used:

brew uninstall --ignore-dependencies python
rm -rf $(pyenv root)
brew uninstall pyenv-virtualenv
brew uninstall pyen

Then to setup MacOs Catalina with Python, I followed this article. The main points from it:

pyenv install 3.7.7

qwerty@qwerty-mbp > python -V
Python 3.7.3 

qwerty@qwerty-mbp > pyenv global 3.7.7

qwerty@qwerty-mbp > pyenv version
3.7.7 (set by /Users/qwerty/.pyenv/version)

qwerty@qwerty-mbp > python -V
Python 3.7.7 

Then I had to reinstall AWS CLI:

sudo rm -rf /usr/local/aws && sudo rm /usr/local/bin/aws

qwerty@qwerty-mbp > python --version
Python 3.6.1

cd /tmp/

curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"

unzip awscli-bundle.zip

sudo /Users/qwerty/.pyenv/shims/python awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

qwerty@qwerty-mbp > /usr/local/bin/aws --version
aws-cli/1.18.53 Python/3.7.7 Darwin/19.4.0 botocore/1.16.3
Theo Sweeny
  • 1,033
  • 14
  • 26
  • I definitely do not recommend this. `brew uninstall --ignore-dependencies python` broke my environment in numerous ways. I couldn't even run `vim` again until I reinstalled the same python version I had before. (Did not expect vim to have a dep on python, but here we are.) – Grant Birchmeier Jul 24 '20 at 16:00