【问题标题】:SSL error after brew install python3 [duplicate]brew install python3后SSL错误[重复]
【发布时间】:2017-10-07 23:29:56
【问题描述】:

我刚刚安装了 python 使用: 酿造安装python3

然后我跑了 pip3 安装虚拟环境

我收到了这个错误: pip 配置了需要 TLS/SSL 的位置,但是 Python 中的 ssl 模块不可用。 收集 virtualenv 无法获取 URL https://pypi.python.org/simple/virtualenv/:确认 ssl 证书时出现问题:无法连接到 HTTPS URL,因为 SSL 模块不可用。 - 跳过 找不到满足 virtualenv 要求的版本(来自版本:) 没有为 virtualenv 找到匹配的分布

如何修复 SSL 错误?

【问题讨论】:

  • 您确定您正在运行您的 brew 安装的 python3 附带的 pip3?检查pip3、python3等的位置
  • @pvg 我检查了 python3 在这里: 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', ] 我不知道如何找到 pip3 目录
  • @alexisdevarennes 我看了看并没有找到解决方案,因为我正在尝试使用自制软件安装 python。我不应该这样做吗?

标签: python ssl homebrew


【解决方案1】:

似乎 brew 跳过了认证步骤。

从我的本地安装复制,这将运行 certifi ssl 安装步骤。

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

然后运行这个:

# 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()

【讨论】:

  • 我运行该代码并收到此错误:f:programming bootadmin$ python3 test.py Traceback(最近一次调用最后一次):文件“test.py”,第 9 行,在 import ssl 中的文件“/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py”,第 101 行 import _ssl # if we can' t 导入它,让错误传播 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):库未加载:/usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  • 哪个错误?你运行 pip install certifi 和 brew install openssl 了吗?
  • 是的,运行 brew install openssl :)
  • @alexidevarennes 我试过了。 pip install certifi 似乎可以工作,但对于 python2 失败了。我在使用 brew install openssl 时遇到了这个错误:警告:拒绝链接:openssl 仅链接小桶 openssl 意味着您在使用 Homebrew 的 openssl 标头时可能最终会链接到不安全、已弃用的系统 OpenSSL。相反,将完整的包含/库路径传递给您的编译器,例如:-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
  • 运行: brew link --force openssl 或添加 export PATH=$(brew --prefix openssl)/bin:$PATH in ~/.bash_profile 或 ln -s /usr/local/Cellar/ openssl/{version}/include/openssl /usr/bin/openssl
猜你喜欢
  • 2019-01-23
  • 1970-01-01
  • 2015-03-09
  • 2018-04-25
  • 1970-01-01
  • 2021-10-04
  • 2022-08-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多