osx 10.13 python SSL报错(ssl module in Python is not available)

待更新。。。

###问题描述

1
2
3
4
5
6
$ pip install pyopenssl --trusted-host pypi.python.org
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting pyopenssl
Could not fetch URL https://pypi.python.org/simple/pyopenssl/: 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 pyopenssl (from versions: )
No matching distribution found for pyopenssl

From Python Developer’s Guide

As of OS X 10.11, Apple no longer provides header files for the deprecated system version of OpenSSL which means that you will not be able to build the _ssl extension.

花了一整天,试过

1
2
3
4
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
export PATH="/usr/local/opt/openssl/bin:$PATH"

还试过

1
brew uninstall openssl && brew install openssl && CFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" pyenv install 3.6.2

最后在python里面

1
2
3
import ssl
import pip
pip.main('install','ipython')

还没权限,安装失败。。。

python -m pip install ipython竟然又可以了,但是ipython not found
最后python -m IPython终于看到了ipython,还没装qtconsole

python的alfred库也要pip安装,心累得不行。。。

Reference

macOS High Sierra: ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib? #993