场景:Mac电脑之前已经通过源码安装了Python3.8,一切都是正常。为了试验asyncio.to_thread方法,又通过源码安装了Python3.9,安装成功之后,创建虚拟环境,发现pip不能用,报错如下
```
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /repository/pypi/simple/aiofiles/
```
解决:去Python3.8的lib-dynload里把ssl对应的.so文件拷贝到3.9里,并把文件名里的38改成39
大致命令如下:
python3.8 -c 'import math;print(math.__file__)'
# /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload/math.cpython-38-darwin.so
cd /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload/
ls *ssl*
# _ssl.cpython-38-darwin.so
python3.9 -c 'import math;print(math.__file__)'
# /usr/local/lib/python3.9/lib-dynload/math.cpython-39-darwin.so
sudo cp _ssl.cpython-38-darwin.so /usr/local/lib/python3.9/lib-dynload/_ssl.cpython-39-darwin.so