windows及linux環境下修改pip的默認鏡像源的方法


1. 在windows環境下

臨時修改 

  使用清華大學的源安裝numpy包。

pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

永久修改

1.1 找到USERPROFILE這個環境變量的地址:

  在cmd中輸入set,找到USERPROFILE的地址(一般情況是在用戶目錄)

 1.2 進入USERPROFILE目錄

  在windows文件管理器中輸入 %APPDATA%,回車。

1.3 在該目錄下新建一個pip目錄和pip.ini文件,pip.ini輸入以下內容:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
disable-pip-version-check = true
timeout = 120
  • index-url:源地址,可以換成其他的源
  • trusted-host :添加源為可信主機,要不然可能報錯
  • disable-pip-version-check:設置為true取消pip版本檢查,排除每次都報最新的pip
  • timeout:超時設置

2. 在linux環境下

2.1 找到默認pip的目錄,修改該目錄下.pip目錄下的pip.conf文件(沒有就自己建)

2.2 修改文件內容

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
disable-pip-version-check = true
國內的鏡像源分別如下:
清華大學: https://pypi.tuna.tsinghua.edu.cn/simple
阿里: https://mirrors.aliyun.com/pypi/simple
豆瓣: http://pypi.douban.com/simple/
中國科學技術大學: https://pypi.mirrors.ustc.edu.cn/simple
華中理工大學: http://pypi.hustunique.com/simple
山東理工大學: http://pypi.sdutlinux.org/simple
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM