공부/문제해결

[Python/virtualenv] WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available

aribae 2024. 10. 25. 14:29

 

 

오늘은 파이썬 패키지 설치 문제를 들고왔어요호

 

항상 지나고보면 삭제-재설치 하는 것이 가장 빠른데

 

괜히 지우기 싫어서 이거저거 해보게되지 않나요? ㅠ^ㅠ

 

 

 

문제상황 - 파이썬 패키지 설치 오류

 

virtualenv에서 로컬 환경과 다른 파이썬 버전을 설치 후 pip install 하니 발생

 

open ssl (TLS/SSL) 미설치로 인한 오류로 확인된다.

 

제안되는 해결 방법 중 하나인 --trusted-host  를 사용해보아도 해결되지 않았다. 

 

더보기

# 오류 메세지 상세 (pip install torch nump tqdm 등등 아무것도 안됨)

pip install -r requirements.txt --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: 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/torchvision/
WARNING: 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/torchvision/
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.")': /simple/torchvision/
WARNING: 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/torchvision/
WARNING: 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/torchvision/
Could not fetch URL https://pypi.org/simple/torchvision/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/torchvision/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement torchvision (from versions: none)
ERROR: No matching distribution found for torchvision

 

 

다시 한 번 확인해보아도 모듈이 없다고 출력.

가상환경이 아닌 로컬 환경에서는 오류메세지가 출력되지 않는다.

python3.10 -c 'import ssl'

 

 

 

 

 

해결방법 - 파이썬 재설치 --with-ssl

 

저는 가상환경에서 필요한 파이썬 버전이 3.10이었는데요,

 

기존 3.10.2를 삭제하고 다시 깔면 깔끔하게 되지 않을 것 같아서 3.10.5를 새로 깔기로 했습니다.

 

테스트용인데 아무거나 작동만 된다면 ...~ 상관없어용

 

 

 

1. (필요시) 라이브러리 설치

 

sudo apt install libssl-dev
sudo apt install zlib1g-dev

 

 

 

2. 원하는 버전의 파이썬 설치

 

 

**** --with-ssl 을 꼭 입력해주세요 !

wget https://www.python.org/ftp/python/3.10.5/Python-3.10.5.tgz 
tar xvf Python-3.10.5.tgz
cd Python-3.10.5
./configure --with-ssl
make altinstall

 

라이브러리간 충돌 방지를 위해 altinstall 으로 해줍니다. 

 

기존꺼 알아서 지워준다네용?

바로 sudo 추가

 

sudo make altinstall

 

 

 

저는 3.10.2도 그대로 있고 3.10.5가 추가로 설치될 줄 알았는데

3.10.5만 남았어용

 

 

 

ssl 정상적으로 import 되는것을 확인하면서 오늘 글은 마무리하도록 하겠습니다.

 

 

 

 

남은 금요일도 화이팅하시고 즐거운 주말되세요 !!  <3