본문 바로가기

Dev

[Linux] requirements.txt 생성하기

설치된 패키지에 대한 정보를 requirements.txt 파일 하나로 만들 수 있다.

새로운 가상환경을 생성하거나 할 때 한번의 명령어로 파일에 정의되어 있는 패키지를 설치할 수 있다.

 

0. requirements.txt 만들기

 

pip freeze > requirements.txt

 

가끔 이렇게 @file 형식으로 버전이 저장되는데,

 

 

그럴 땐 아래 명령어로 파일을 생성하면 된다

 

pip list --format=freeze > requirements.txt

 

해결

 

1. requirements.txt 파일로 패키지 설치하기

 

해당 파일에 있는 패키지 설치시 아래 명령어를 입력하면 된다

 

pip install -r requirements.txt

 

설치가 되지않는 패키지는 뛰어넘고 설치 가능한 패키지만 모두 설치 시 (Linux와 CentOS에서만)

 

cat requirements.txt | xargs -n 1 pip install

 

끝!