Python 패키지 오프라인 다운로드 및 설치
Python 개발/운영 환경을 셋팅할 때...
개발 환경에서는 인터넷을 쓸 수 있는데 운영 환경에서는 인터넷을 쓸 수 없는 경우가 있어서...
아래와 같은 방법을 사용하고 있습니다.
1. pip 를 이용하여 현재 사용중인 패키지 리스트를 백업받는다. (새 폴더 하나 만들어서 그 곳에서 실행하세요)
1 |
py -3.6 -m pip freeze > requirements.txt |
cs |
이렇게 하면 requirements.txt 파일에 현재 사용중인 패키지 리스트를 백업받는다.
* requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
APScheduler==3.3.1 certifi==2017.7.27.1 chardet==3.0.4 gevent==1.2.2 greenlet==0.4.12 grequests==0.3.0 idna==2.6 psycopg2==2.7.3 pytz==2017.2 redis==2.10.5 requests==2.18.4 six==1.10.0 tzlocal==1.4 urllib3==1.22 |
cs |
2. pip 를 이용하여 requirements.txt 에 리스트된 패키지를 다운로드 받는다. (오프라인 백업)
1 |
py -3.6 -m pip download -r .\requirements.txt |
cs |
이렇게 하면 아래와 같이 패키지 파일을 백업받을 수 있습니다.
3. 새로이 Python 환경을 설정할 PC 에다가 위에서 생성한 파일들을 모두 복사한다.
4. pip 를 이용해 로컬 폴더에서 Python 패키지를 설치한다. (인터넷을 사용하지 않음)
1 |
py -3.6 -m pip install --no-index --find-links="./" -r .\requirements.txt |
cs |
--no-index 와 --find-links 의 의미는 다음과 같다.
1 2 3 4 5 6 |
--no-index Ignore package index (only looking at --find- links URLs instead). -f, --find-links <url> If a url or path to an html file, then parse for links to archives. If a local path or file:// url that's a directory, then look for archives in the directory listing. |
cs |
끝 !
2018-06-08, 업데이트 사항이 있는 패키지 리스트 확인
pip list --outdated --format=legacy