经过几天的努力,我已经解决了这个问题。适用于MAC OS X El Captian或更高版本。
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
sudo rm -rf "/Applications/Python 2.7"
cd /usr/local/bin/
ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print $9}' | tr -d @ | xargs rm
brew uninstall python
brew uninstall openssl
brew link --force openssl
现在使用brew重新安装python和openssl。
brew install openssl
brew install python --with-brewed-openssl
在你的MAC的~/.bash_profile中添加下面的内容到环境变量PATH中。
vi ~/.bash_profile
export PATH=/usr/local/opt/openssl/bin:/usr/local/opt/python/libexec/bin:$PATH
重新启动终端
python --version (verify if it is picking up the right version)
openssl version -a (verify if it is picking up the right version)
python -c "import ssl; print ssl.OPENSSL_VERSION"
(注意:如果您安装了Python3,则需要在内联编译器步骤中更新print
语法)
python -c "import ssl; print(ssl.OPENSSL_VERSION)"
应该为您提供最新版本的OPEN SSL版本
Modules/Setup.dist
中可以看到:-L$(SSL)/lib -lssl -lcrypto
。如果是动态的,他只需要设置LD_PRELOAD
,指向0.9.8共享对象,然后启动Python即可。 - jwwssl.OPENSSL_VERSION
底层实现,如果是动态的,它将显示加载的库(而不仅仅是最初链接的库),因此值得尝试LD_PRELOAD
。 - Paul Kehrer