Posted on 

pip命令行集锦

代理

python pip设置代理

有三种常用方式:

①永久设置:

1
2
3
4
vim /etc/profile:
export http_proxy='http://代理服务器IP:端口号'
export https_proxy='http://代理服务器IP:端口号'
source /etc/profile

②临时设置(重连后失效):

也可以直接运行

1
2
export http_proxy='[http://代理服务器IP](http://xn--ip-bf3cz5lfxfo83ageu/):端口号
export https_proxy='[http://代理服务器IP](http://xn--ip-bf3cz5lfxfo83ageu/):端口号'

注意:设置之后可能使用ping时还是无法连接外网,但是pip时可以的,因为ping的协议不一样不能使用这个代理

③单次设置:(推荐使用

直接在pip时设置代理也是可以的:

1
pip install -r requirements.txt --proxy=代理服务器IP:端口号

pip配置国内源

配置pip.conf

1
2
3
mkdir ~/.pip/
sudo vim ~/.pip/pip.conf
12

加入下面的代码即可

1
2
[global] 
index-url = https://pypi.tuna.tsinghua.edu.cn/simple