首頁  >  問答  >  主體

如何配置國內的pypi鏡像來源?

PyPI (Python Package Index) 是 Python 程式語言的軟體儲存庫。開發者可以透過 PyPI 尋找和安裝由 Python 社群開發和共享的軟體,也可以將自己開發的程式庫上傳至 PyPI 。

那麼如何配置國內的pypi鏡像來源呢

萌褚萌褚1073 天前1219

全部回覆(5)我來回復

  • yntdx

    yntdx2021-11-11 09:08:12

    用的是小鳥雲端伺服器,之前直接使用pip安裝,由於pip預設安裝源位於國外,速度很慢而且經常斷鍊,導致無法正常安裝擴充包。後來用-i(長格式:--index)參數,可將安裝來源暫時指向國內源。也可以透過設定pip來源設定檔的方式永久更改pip來源。永久修改 Linux系統 Linux下,修改~/.pip/pip.conf (沒有就創建一個資料夾及檔案。資料夾要加“.”,表示是隱藏資料夾) [global]index-url = http:/ /mirrors.aliyun.com/pypi/simple/[install]trusted-host=mirrors.aliyun.com Windows系統 在「C:\Users\你的使用者名稱\」目錄下建立「pip」目錄,「pip」目錄下方建立“pip.ini”檔案(注意:以UTF-8 無BOM格式編碼)。 「pip.ini」文件內容: [global]index-url = http://mirrors.aliyun.com/pypi/simple/[install]trusted-host=mirrors.aliyun.com 在window下面用記事本、notepad等編輯檔案的時候,如果儲存為UNICODE或UTF-8,分別會在檔案的開頭加上兩個位元組「\xFF\xFE」和三個位元組「\xEF\xBB\xBF」。即:BOM。此時pip在讀取設定檔時會回報"ConfigParser.MissingSectionHeaderError: File contains no section headers."錯誤,此時採用以下Python腳本對pip.ini進行處理即可: import redef remove_BOM(config_path): (config_path).read()  content = re.sub(r"\xfe\xff","", content)  content = re.sub(r"\xff\xfe","", content) contentcontent re. (r"\xef\xbb\xbf","", content)  open(config_path, 'w').write(content)if __name__ == '__main__':    config_path = "C:\User'__main__':    config_path = "C:\Users\Administrator\Users\Admini .ini"  # 此處路徑修改為你的設定檔所對應地路徑    remove_BOM(config_path)  

    ######################################################

    回覆
    0
  • hehahha

    hehahha2021-11-09 15:55:34

    阿里雲官方鏡像來源:

    https://developer.aliyun.com/mirror/?utm_content=g_1000303593

    #PyPI 鏡像來源設定方法

    a. 找到下列檔案

    ~/.pip/pip.conf

    b. 在上述文件中新增或修改:

    [global]
    index-url = https://mirrors.aliyun.com/pypi/simple/
    [install]
    trusted-host=mirrors.aliyun.com

    回覆
    0
  • 取消回覆