背景
由於 python 自帶的源下載速度非常慢,特別是安裝一些庫的時候,甚至有時會失敗。
因此,建議將下載源替換成國內的,下載速度會快很多。總共有兩種方法
- 代碼替換 (推薦使用這一種)
- 手動替換
代碼替換
設置阿里源(推薦這個)
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
pip config set install.trusted-host mirrors.aliyun.com
設置清華大學的
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn
手動替換
windows 替換
首先在 windows 當前用户家的目錄下,創建一個 pip 文件夾,然後創建一個pip.ini文件,修改文件內容為如下;
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
- 記得一定是pip.ini,如果沒有開後綴的同學,記得把文件後綴打開,再修改文件的後綴為ini即可。
- 用户家目錄為
C:Users**** # **** 就是當前登錄用户名, 比如登錄用户名是Luke, 那麼就是C:/Users/junxu
Mac 替換
會在目錄下自動生成,不同系統,目錄可能不同,所以使用命令行最靠譜
~/.config/pip/pip.conf
[global]
index-url = https://mirrors.aliyun.com/pypi/simple
[install]
trusted-host = mirrors.aliyun.com
國內源列表(推薦用阿里雲的)
阿里雲: http://mirrors.aliyun.com/pypi/simple/
中國科技大學: https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣: http://pypi.douban.com/simple/
清華大學: https://pypi.tuna.tsinghua.edu.cn/simple/
中國科學技術大學: http://pypi.mirrors.ustc.edu.cn/simple/