Translate

2024/04/08

PIP Installation Error: SSLCertVerificationError

pip 패키지 설치 시, SSLCertVerificationError 해결방법

Python은 프로그래밍 언어로서 가장 널리 사용되고 있으며, 풍부한 라이브러리와 패키지를 제공합니다. 이러한 패키지들은 pip를 통해 간편하게 설치할 수 있습니다. 그러나 때로는 회사 네트워크 환경에서 SSL 인증서 오류로 인해 pip 패키지 설치가 실패하는 경우가 있습니다. 본 포스팅에서는 이러한 SSLCertVerificationError를 해결하는 방법을 소개하고 있습니다.



현상

pip install requests

pip를 사용하여 패키지를 설치할 때 아래와 같이 SSLCertVerificationError 오류가 발생하는 경우가 있습니다.

...
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(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)'))) - skipping
WARNING: There was an error checking the latest version of pip.

또는

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)'))': /simple/pytorch/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)'))': /simple/pytorch/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)'))': /simple/pytorch/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)'))': /simple/pytorch/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)'))': /simple/pytorch/
Could not fetch URL https://pypi.org/simple/pytorch/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pytorch/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)'))) - skipping
ERROR: Could not find a version that satisfies the requirement pytorch (from versions: none)
ERROR: No matching distribution found for pytorch
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(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)'))) - skipping
WARNING: There was an error checking the latest version of pip.


원인

이 오류는 주로 회사 내부 네트워크 환경에서 발생하며, 방화벽이나 프록시 서버 등의 설정으로 인해 SSL 인증서 확인이 실패하기 때문니다.



해결방법

방법1방법2 둘 중 하나만 선택하여 해결한다.


1. 명령어 옵션을 통한 해결

설치 시, 아래와 같이 옵션을 주어 "pypi.org"와 "files.pythonhosted.org"를 무조건 신뢰하도록 한다.

pip --trusted-host pypi.org --trusted-host files.pythonhosted.org install (설치할 라이브러리명)

2. pip 환경설정

pip 환경설정 파일을 설정하여 pip install 명령어만 가지고 설치가 가능하도록 한다. pip 환경설정 파일 위치는 운영체제마다 다르기 때문에 운영제체별로 위치를 확인하고 해당 위치에 pip 환경설정 파일이 없을 경우 파일을 만들어서 아래 내용을 추가한다.

 [global]
 trusted-host = pypi.org
                files.pythonhosted.org

<운영체제별 pip.ini 위치>

  • 리눅스: $HOME/.pip/pip.conf
  • 윈도우: %HomePath%\pip\pip.ini

참고: Configuration - pip documentation v23.0 (pypa.io)


설정 후 아래 명령어를 이용하여 설정이 적용되었는지 확인한다.

pip config list

적용이 되었다면 아래와 같은 알림을 볼 수 있다.

global.trusted-host='pypi.org files.pythonhosted.org'

설정이 적용 되지 않았으면 빈 알림만 출력된다. 이후 설치하고자 하는 패키지를 다시 설치한다.

위 방법 중 하나를 선택하여 진행하면 SSLCertVerificationError 오류를 해결할 수 있습니다. 회사 네트워크 환경에 따라 적절한 방법을 선택하시기 바랍니다.



결론

pip 패키지 설치 시 SSLCertVerificationError 오류가 발생하면 회사 네트워크 환경 때문일 가능성이 높습니다. 이 경우 명령어에 --trusted-host 옵션을 주어 pypi.org와 files.pythonhosted.org를 신뢰하도록 하거나, pip 환경설정 파일에 trusted-host 항목을 추가하는 방식으로 해결할 수 있습니다. 두 가지 방법 중 하나를 선택하여 진행하면 SSL 인증서 확인 오류 없이 pip 패키지 설치가 가능해집니다. 회사 네트워크 정책에 따라 적절한 해결책을 택하시기 바랍니다.

댓글 없음:

댓글 쓰기

Template by Aliya H.