파이썬 패키지 수동 설치하는 방법(pip 오프라인 설치)

파이썬을 오프라인에서 패키지 설치하는 방법을 알아보겠습니다.

 

가장 먼저 할일은 패키지의 상태를 확인하는 것입니다.

 

설치된 패키지 확인

pip freeze 명령어를 통해서 패키지를 확인할 수 있습니다.

pip freeze

etc-image-0

이후 원하는 패키지를 다운로드 받아야 하는데요.

 

Pypl에서 검색하여 사용할 수 있습니다.

https://pypi.org/

 

PyPI · The Python Package Index

The Python Package Index (PyPI) is a repository of software for the Python programming language.

pypi.org

 

 

etc-image-1

저의 경우 xlrd가 없다고 나왔으니

etc-image-2

download files를 통해서 whl 파일을 다운로드 받습니다.

 

이후 python -m pip install 패키지명으로 설치하면 되는데요.

 

etc-image-3

 

간혹 SSL에러가 뜰수 있습니다.

 

바로 아래와 같이 confirming the ssl certificate라는 에러인데요.

python -m pip install xlrd-2.0.1-py2.py3-none-any.whl

WARNING: Requirement 'xlrd-2.0.1-py2.py3-none-any.whl' looks like a filename, but the file does not exist
Processing c:\python\xlrd-2.0.1-py2.py3-none-any.whl
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'C:\\python\\xlrd-2.0.1-py2.py3-none-any.whl'
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:1129)'))) – skipping

 

이때에는 아래처럼 믿을 수 있는 호스트로 pypi.org를 설정해줍니다.

 

pip --trusted-host pypi.org --trusted-host files.pythonhosted.org install 라이브러리명

 

이렇게 하면 자동으로 설치되게 됩니다.

etc-image-4

오프라인 시스템에서는 파이선 패키지 설치에 애로사항이 많은데요.

 

그리고 의존성 패키지를 한번에 설치하는 것은 외부망이 되는 PC에서 아래 명령어를 통해서 패키지를 일괄로 다운받을 수 있습니다.

 

pip download 패키지명 -d /폴더경로

 

아래와 같은 방법으로 작업할 수 있으니 참고해보시기 바랍니다.