Search code examples
python-3.xopensslpyenv

How to solve ImportError: cannot import name 'ssl' on Python 3


I am using pyenv with Python 3.6.0 on a MAC OS Catalina V10.15.5. I have updated openssl with brew to the latest version ([email protected]):

brew install openssl

But now I am getting the following errors in my Python virtual environments, for instance when using Boto3:

from urllib3.util.ssl_ import ( ImportError: cannot import name 'ssl'

How can I link back my pyenv environments to SSL?


Solution

  • I was recently facing the same issue. The solution is forcing the reinstallation of the Python versions you are using within your virtual envs.

    For instance for Python 3.6.0:

    pyenv install -f 3.6.0
    

    Output:

    python-build: use openssl from homebrew
    python-build: use readline from homebrew
    Installing Python-3.6.0...
    python-build: use readline from homebrew
    python-build: use zlib from xcode sdk
    Installed Python-3.6.0 to /Users/andrew/.pyenv/versions/3.6.0
    

    As you see in the output: "python-build: use openssl from homebrew" it will link Python to the current openssl version defined by Homebrew.