Python學習筆記-- 利用pip安裝模組,pythonpip

來源:互聯網
上載者:User

Python學習筆記-- 利用pip安裝模組,pythonpip

我們在使用Python時經常需要安裝各種模組,而pip是一個很強大的模組安裝工具,類似於linux的Yum一樣,安裝模組時能自動解決依賴等,總結如下:

 

一、安裝pip:

  安裝python時自動會安裝pip

 

二、使用pip:

  1、升級pip

    python -m pip install --upgrade pip

  2、安裝模組

    pip install gevent  #安裝指定模組

    pip install -r  requirements.txt     # 安裝requirements.txt檔案中定義的模組列表

 

三、更改pip源

  pip安裝第三方模組時,預設從Python官方模組庫:https://pypi.python.org下載,但由於經常被防火牆所擋或下載速度慢等原因,因此需要更換下國內鏡像

 

  網上有很多可用的源,例如

    豆瓣:http://pypi.douban.com/simple/
    清華:https://pypi.tuna.tsinghua.edu.cn/simple

  最近使用得比較多並且比較順手的是清華大學的pip源,它是官網pypi的鏡像,每隔5分鐘同步一次,地址為 https://pypi.tuna.tsinghua.edu.cn/simple

  1、臨時使用:

    可以在使用pip的時候加參數-i https://pypi.tuna.tsinghua.edu.cn/simple

    例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple gevent,這樣就會從清華這邊的鏡像去安裝gevent庫。

  2、
永久修改,一勞永逸


    Linux下,修改 ~/.pip/pip.conf (沒有就建立一個), 修改 index-url至tuna,內容如下:


    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple

    Windows下,直接在user目錄中建立一個pip目錄,如:C:\Users\xx\pip,建立檔案pip.ini,內容如下

    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple

    

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.