mac環境 python3.7安裝 ssl module 及 lzma.py 報錯解決

emmm, 折騰了三個小時的環境。import ssl 報錯 No module named ‘_ssl’
吐槽一波後,還是要處理哇

環境:mac
python版本:3.7

1 No module named '_ssl’最終解決方式

  • 1 確認是否安裝ssl
查看openssl版本 openssl version
                OpenSSL 1.0.2s
                
確認是否有相關頭文件
sudo find / -name ssl.h

安裝了,文件齊的,版本也是適配的

  • 2 指定ssl再編譯
./configure --with-ssl

configure: WARNING: unrecognized options: --with-ssl

help看一下,確實沒有這個configure選項,可以支持的是 with-openssl; 需要指定路徑,openssl的路徑是啥 ??

  • 3 查看openssl路徑前綴
brew --prefix openssl
原來是 /usr/local/opt/openssl

重新編譯 ./configure --with-openssl=/usr/local/opt/openssl
終於看到了結果:
checking for openssl/ssl.h in /usr/local/opt/openssl/... yes
  • 4 make clean & make & make install

  • 5 import ssl驗證,終於ok

繞的彎

  • 改環境變量
echo 'export LDFLAGS="-L/usr/local/opt/openssl/lib"' >> ~/.bash_profile
echo 'export CPPFLAGS="-I/usr/local/opt/openssl/include"' >> ~/.bash_profile
  • 改代碼
setup.py 這裏繞的太多了

2 Could not import the lzma module最終解決方式

出一個坑,進下一個坑,pip3安裝pandas後使用時

Could not import the lzma module. Your installed Python is incomplete.
  • 1 第一反應pip3安裝
pip3 install lzma 
Could not find a version that satisfies the requirement lzma (from versions: none)
  • 2 百度了半天,安裝了 backports.lzma

把lzma.py第27行左右的代碼改爲如下:

try:
    from _lzma import *
    from _lzma import _encode_filter_properties, _decode_filter_properties
except ImportError:
    from backports.lzma import *
    from backports.lzma import _encode_filter_properties, _decode_filter_properties
import _compression
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章