2017. 3. 10. 09:46

python의 pip 경로를 mirror 서버로 변경하기

보안적 이슈(네트웍 방화벽, proxy, ...)든, 속도 이슈가 되든,

기본적인 python pip에서 사용하는 url을 daum으로 변경할 필요가 있습니다.

pip 설정 파일(pip.ini / pip.conf) 이용하기

pip 설정 파일을 이용하면, command line 수정 없이 진행할 수 있다.
그렇기 때문에 다른 script나 응용 프로그램에서 pip를 호출해도 쉽게 호환성을 유지할 수있다.
pip 설정 파일의 내용은 아래와 같다.[global]

[global]
index-url=http://ftp.daumkakao.com/pypi/simple
trusted-host=ftp.daumkakao.com
proxy=http://xxx.xxx.xxx.xxx:xxxx

만일 proxy를 사용하지 않는다면, proxy=... 부분은 없어도 된다.

Windows 라면,

%appdata%\.pip\pip.ini

Linux 라면,

$HOME/.pip/pip.conf

에 저장한다.

마일 잘 안되는 경우, 아래 command line 방식으로 할 수 밖에 없다.

(참고)

Linux에서

sudo pip install ...

하는 경우, pip 경고 문구가 발생하는 경우가 있다.

이때는, sudo -H를 사용하라고 하는데, sudo -H인 경우, 위 pip.conf 파일이 다음 경로에도 복사되어야 제대로 동작한다.

/root/.pip/pip.conf

pip command line 이용하기

proxy 환경인 경우

Windows라면,

SET http_proxy=http://xxx.xxx.xxx.xxx:xxxx

만약 linux 계열이고, proxy 설정이 안되어 있다면,

export http_proxy=http://xxx.xxx.xxx.xxx:xxxx

를 수행한다.

이제 아래와 같이 pip를 실행하자.

pip install XXXXX -i http://ftp.daumkakao.com/pypi/simple
 
혹시,


Collecting XXXXX

  The repository located at ftp.daumkakao.com is not a trusted or secure host an

d is being ignored. If this repository is available via HTTPS it is recommended

to use HTTPS instead, otherwise you may silence this warning and allow it anyway

s with '--trusted-host ftp.daumkakao.com'.

  Could not find a version that satisfies the requirement django (from versions:

 )

No matching distribution found for XXXXX
 
와 같이 오류가 발생한다면, (대략 python 3.x)

pip install XXXXX -i http://ftp.daumkakao.com/pypi/simple --trusted-host ftp.daumkakao.com

를 실행하면 pip를 실행할 수 있다.