1. 程式人生 > >pip更改國內源

pip更改國內源

完成 相同 阿裏雲 conf 科學技術 -i 就是 href 直接

pip更改國內源

國內源:

  • 豆瓣:http://pypi.douban.com/simple/
  • 清華:https://pypi.tuna.tsinghua.edu.cn/simple
  • 阿裏雲: http://mirrors.aliyun.com/pypi/simple/
  • 中國科技大學: https://pypi.mirrors.ustc.edu.cn/simple/
  • 中國科學技術大學: http://pypi.mirrors.ustc.edu.cn/simple/

使用方法

1. 臨時使用

如果只是臨時使用,可以使用-i 加源的方式,如:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple 模塊名

註意:如果是http方式的pip源,默認是不安全的,需要增加--trusted-host選項,如:

pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 模塊名

2. 永久更改

linux修改配置文件

修改 ~/.pip/pip.conf配置文件,沒有就創建一個,修改 index-url至你需要的pip源,內容如下:

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

http方式的配置文件如下:

[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com

windows修改配置文件

直接在user目錄中創建一個pip目錄,如:C:\Users\watson\pip,新建文件pip.ini,內容如下:

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

其中index-url就是你選擇的pip源
http方式的配置文和linux下的配置文相同。
新建文件完成後,在環境變量Path後追加:%USERPROFILE%\pip\pip.ini。

pip更改國內源