5

I just installed python using: brew install python3

I then ran pip3 install virtualenv

I got this error: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Collecting virtualenv Could not fetch URL https://pypi.python.org/simple/virtualenv/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping Could not find a version that satisfies the requirement virtualenv (from versions: ) No matching distribution found for virtualenv

How do I fix the SSL error?

Harry L
  • 95
  • 1
  • 7
  • 1
    You sure you're running the pip3 that came with your brew-installed python3? Check the location of pip3, python3, etc. – pvg Oct 07 '17 at 23:32
  • Please see: https://stackoverflow.com/questions/41489439/pip3-installs-inside-virtual-environment-with-python3-6-failing-due-to-ssl-modul/42798679 – alexisdevarennes Oct 08 '17 at 00:11
  • @pvg I checked python3 is here: sys.path = [ '/Users/bootadmin', '/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/site-packages', '/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages', ] I wasn't sure how to find the pip3 directory – Harry L Oct 08 '17 at 00:14
  • @alexisdevarennes I looked at that and didn't find a solution because I am trying to use homebrew to install python. Should I not do that? – Harry L Oct 08 '17 at 00:17

1 Answers1

2

Seems brew skipped the certifi step.

Copied from my local installation, this runs the certifi ssl install step.

brew install openssl
ln -s /usr/local/Cellar/openssl/{version}/include/openssl /usr/bin/openssl
pip install certifi

Then run this:

# install_certifi.py
#
# sample script to install or update a set of default Root Certificates
# for the ssl module.  Uses the certificates provided by the certifi package:
#       https://pypi.python.org/pypi/certifi

import os
import os.path
import ssl
import stat
import subprocess
import sys

STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
             | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP
             | stat.S_IROTH |                stat.S_IXOTH )


def main():
    openssl_dir, openssl_cafile = os.path.split(
        ssl.get_default_verify_paths().openssl_cafile)

    print(" -- pip install --upgrade certifi")
    subprocess.check_call([sys.executable,
        "-E", "-s", "-m", "pip", "install", "--upgrade", "certifi"])

    import certifi

    # change working directory to the default SSL directory
    os.chdir(openssl_dir)
    relpath_to_certifi_cafile = os.path.relpath(certifi.where())
    print(" -- removing any existing file or link")
    try:
        os.remove(openssl_cafile)
    except FileNotFoundError:
        pass
    print(" -- creating symlink to certifi certificate bundle")
    os.symlink(relpath_to_certifi_cafile, openssl_cafile)
    print(" -- setting permissions")
    os.chmod(openssl_cafile, STAT_0o775)
    print(" -- update complete")

if __name__ == '__main__':
    main()
alexisdevarennes
  • 5,437
  • 4
  • 24
  • 38
  • I ran that code and got this error: f:programming bootadmin$ python3 test.py Traceback (most recent call last): File "test.py", line 9, in import ssl File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 101, in import _ssl # if we can't import it, let the error propagate ImportError: dlopen(/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload/_ssl.cpython-36m-darwin.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib – Harry L Oct 08 '17 at 00:22
  • Which error? did you run pip install certifi and brew install openssl? – alexisdevarennes Oct 08 '17 at 00:23
  • Yup run brew install openssl :) – alexisdevarennes Oct 08 '17 at 00:24
  • @alexidevarennes I tried those. pip install certifi seemed to work but failed for the python2. I ran into this error with brew install openssl: Warning: Refusing to link: openssl Linking keg-only openssl means you may end up linking against the insecure, deprecated system OpenSSL while using the headers from Homebrew's openssl. Instead, pass the full include/library paths to your compiler e.g.: -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib – Harry L Oct 08 '17 at 00:30
  • Run: brew link --force openssl OR add export PATH=$(brew --prefix openssl)/bin:$PATH in ~/.bash_profile OR ln -s /usr/local/Cellar/openssl/{version}/include/openssl /usr/bin/openssl – alexisdevarennes Oct 08 '17 at 00:31
  • brew link --force openssl gave the same - refusing to link error how do I do this one? add export PATH=$(brew --prefix openssl)/bin:$PATH in ~/.bash_profile for the ln -s, I got ln: /usr/bin/openssl: Operation not permitted – Harry L Oct 08 '17 at 02:41