為什么要換源?
Python第三方庫下載默認鏡像源在國外,因為特殊的原因在國內的你我利用這個鏡像源往往速度會非常地慢,因此為了提速將這個默認鏡像源換成國內的鏡像源是非常有必要的。
鏡像源的種類有哪些?
- 國外鏡像源——官方
https://pypi.python.org/simple
- 國內鏡像源——常用
清華鏡像源 https://pypi.tuna.tsinghua.edu.cn/simple
阿里云鏡像源 http://mirrors.aliyun.com/pypi/simple
中科大鏡像源 https://pypi.mirrors.ustc.edu.cn/simple
換源的方法有哪些?
- 全局替換——一勞永逸
win+R鍵進入shell終端,在shell終端輸入以下命令
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
- 單次替換
在shell終端輸入以下命令
pip install -i <鏡像源> <第三方庫名>
例如:此次安裝pandas第三方庫是在清華鏡像源中拉取的pandas
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas