======
什麼是鏡像
爲什麼叫鏡像,是因爲鏡像站每隔一段時間(幾分鐘)便會使自己和國外源保持同步,維持和國外源一模一樣的軟件資源列表,就像照鏡子一樣(即它從國外下載,我們從它那下載,它是我們的中間媒介)
除了python第三方庫下載工具pip,node.js等衆多編程語言也可以設置爲國內鏡像,另外homebrew也可以設置更換鏡像源
爲什麼要使用鏡像源
Python的服務器是在國外的,但因爲國外官方pypi經常被牆,導致我們用pip3安裝模版庫是速度極慢,所以我們最好是將自己使用的pip源更換一下,解決被牆導致的裝不上庫的煩惱
國內常用鏡像源
清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
阿里雲 http://mirrors.aliyun.com/pypi/simple/
中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
推薦使用清華大學鏡像源,清華大學開源鏡像站是專門有個社團在運營的,所以是非常可靠的,而且每隔5分鐘同步一次
pip臨時使用鏡像源
原始源:https://pypi.python.org/simple
只需在使用pip3的時候加參數-i https://pypi.tuna.tsinghua.edu.cn/simple
即可從清華大學鏡像站安裝python第三方庫
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple gevent
這樣就可以從清華大學鏡像站去安裝gevent庫,可以看到速度快得飛起(9.2MB/S)
一勞永逸更換pip鏡像源
Mac用戶只需在終端輸入
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
可以看到設置寫到了/Users/macos/.config/pip/pip.conf
文件中(這個文件原來是沒有的)
安裝jieba庫,測試成功!
一勞永逸更換PyCharm鏡像源
安裝示例:
參考資料
======
Mac下brew更換國內鏡像源
brew 是一個很好地Mac下管理應用包的工具,可是第一次安裝後直接使用時,下載和更新很慢,這是因爲brew的鏡像源在國外,我們的網絡訪問會很慢,不過我們可以修改鏡像源爲國內
使用清華鏡像源
在終端一次運行如下每一行代碼
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
brew update
在使用過最後brew update後,需要等待一部分時間,大概一分鐘,如果看見終端上方一直在變化就離成功不遠了,最後會在終端中顯示更新信息,就算是大功告成了
復原
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update