pip和conda在安裝第三方庫(kù)時(shí),都是默認(rèn)從國(guó)外的官方網(wǎng)站上下載,導(dǎo)致我們很多時(shí)候安裝的速度很慢或者直接失敗,這時(shí)候切換國(guó)內(nèi)源可以很好的解決這一問(wèn)題。
1 pip切換國(guó)內(nèi)源
1.1 臨時(shí)切換
進(jìn)入命令行(window下“win+R” 進(jìn)入cmd)
在使用pip安裝時(shí)加 -i 參數(shù),并指定國(guó)內(nèi)源鏈接:
pip install SomePackage(庫(kù)的名字) -i https://pypi.tuna.tsinghua.edu.cn/simple
1.2 永久切換
windows下,在C:\Users\(你的用戶名)\AppData\Roaming目錄下新建文件夾pip
在pip文件夾下新建pip.ini文件,然后在pip.ini 里輸入(可以先建立.txt文件,再更改后綴名為.ini):
[global]
timeout = 6000
index-url =https://pypi.tuna.tsinghua.edu.cn/simple/
trusted-host = pypi.douban.com
保存后再使用pip install 命令,就會(huì)發(fā)現(xiàn)速度快了很多。
國(guó)內(nèi)源有很多,有的維護(hù)的并不好,當(dāng)一個(gè)源出現(xiàn)問(wèn)題時(shí),我們可以再修改鏈接到另一個(gè)源。
常用的國(guó)內(nèi)源:
豆瓣 http://pypi.douban.com/simple/
阿里云 http://mirrors.aliyun.com/pypi/simple/
中國(guó)科技大學(xué) https://pypi.mirrors.ustc.edu.cn/simple/
清華大學(xué) https://pypi.tuna.tsinghua.edu.cn/simple/
2 conda切換國(guó)內(nèi)源
進(jìn)入命令行(window下“win+R” 進(jìn)入cmd)
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
前兩行命令為添加源,最后一行命令為設(shè)置搜索時(shí)顯示通道地址。
國(guó)內(nèi)源有時(shí)候因?yàn)榘鏅?quán)等問(wèn)題會(huì)關(guān)閉,當(dāng)一個(gè)源出現(xiàn)問(wèn)題時(shí),我們可以再修改鏈接到另一個(gè)源。
常用國(guó)內(nèi)源:
中科大源:
https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
清華源:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
其他源:
https://mirrors.aliyun.com/pypi/
https://pypi.doubanio.com/simple/
查看已經(jīng)添加的源:
conda config --show channels
顯示conda的config配置:
conda config --show
換回conda的默認(rèn)源:
conda config --remove-key channels
寫(xiě)在后面
- 上面的內(nèi)容都是在windows下的,不過(guò)對(duì)于Linux和Mac,命令也幾乎是一致的。
- 作者水平有限,如果有文章中有錯(cuò)誤的地方,歡迎指正!如有侵權(quán),請(qǐng)聯(lián)系作者刪除。