반응형

설치시 다운로드한 Python 패키지가 저장되어 있는 캐시(cache)를 삭제하는 방법을 다룹니다. 



2024. 3. 16 최초작성




pip cache에는 pip 명령으로 설치시 다운로드된 Python 패키지나  소스코드로부터 필드된 Python 패키지가 저장되어 있습니다. 때때로 버전 충돌등으로 인해 또는 디스크 공간 절약을 위해 pip cache에 있는 Python 패키지를 삭제해야 할 필요가 생길 수 있습니다. 



PyTorch나 Tensorflow 등의 패키지를 설치한 경우 pip cache가 많은 디스크 공간을 사용합니다.




다음 명령으로 pip cache 정보를 확인할 수 있습니다. 캐시가 사용하는 경로와 현재 사용한 디스크 크기, 파일 개수 등이 표시됩니다. 

 

(base) webnautes@webnautes-laptop:~$ pip cache info

Package index page cache location (pip v23.3+): /home/webnautes/.cache/pip/http-v2

Package index page cache location (older pips): /home/webnautes/.cache/pip/http

Package index page cache size: 3737.2 MB

Number of HTTP files: 384

Locally built wheels location: /home/webnautes/.cache/pip/wheels

Locally built wheels size: 36 kB

Number of locally built wheels: 2



다음 명령으로 pip cache의 경로를 확인할 수 있습니다.

 

(base) webnautes@webnautes-laptop:~$ pip cache dir

/home/webnautes/.cache/pip



다음 명령으로 pip cache에 있는 모든 Python 패키지를 제거합니다.



(base) webnautes@webnautes-laptop:~$ pip cache purge

Files removed: 386




다시 확인해보면 캐시가 사용하는 디스크 크기 항목과 파일 개수가 모두  0이 된것을 볼 수 있습니다.

 

(base) webnautes@webnautes-laptop:~$ pip cache info

Package index page cache location (pip v23.3+): /home/webnautes/.cache/pip/http-v2

Package index page cache location (older pips): /home/webnautes/.cache/pip/http

Package index page cache size: 0 bytes

Number of HTTP files: 0

Locally built wheels location: /home/webnautes/.cache/pip/wheels

Locally built wheels size: 2.2 kB

Number of locally built wheels: 0



pip cache에서 패키지 하나만 삭제할 필요가 있는 경우에는 다음 명령을 사용하세요.

 

pip cache remove 패키지이름





참고

 

https://linuxhandbook.com/clear-pip-cache/


반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts