起こったこと
pythonでsklearnをインポートしようとしたら
No module named sklearn
と表示された。
しかし以前 sklearn を使った時はこのような表示はされなかったため、不思議に思いつつも、pip を使い sklearn をインストールしようと試みるが
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting sklearn
Retrying (Retry(total=4, 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.”)’: /simple/sklearn/
Retrying (Retry(total=3, 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.”)’: /simple/sklearn/
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.”)’: /simple/sklearn/
Retrying (Retry(total=1, 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.”)’: /simple/sklearn/
Retrying (Retry(total=0, 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.”)’: /simple/sklearn/
Could not fetch URL https://pypi.org/simple/sklearn/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.org’, port=443): Max retries exceeded with url: /simple/sklearn/ (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)) – skipping
Could not find a version that satisfies the requirement sklearn (from versions: )
No matching distribution found for sklearn
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.org’, port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)) – skipping
という長ったらしい文が出てきた。
自分で訳してみたは良いものの、読むことはできたが意味がよくわからず。
HTTP や SSL と出てきているところから、セキュリティの問題なのではないかと推測。
わかる方がいたらぜひご教授願いたい。

解決方法
ググってみても良さげな解決策が見つからなかったため、今回sklearnを使おうとした時と前回とで何が違うのか考えてみた。
すると source の設定が思い当たった。
早速 which python で確認してみると案の定
/usr/bin/python
となっていたため、source ~/.zshrcと入力し、再度 sklearn のインポートを試みたらうまくいった。



