pip介紹與使用

來源:互聯網
上載者:User

標籤:python   pip   pip freeze   requirements.txt   

一、簡介  

  pip 是一個安裝和管理 Python 包的工具,python安裝包的工具有easy_install, setuptools, pip,distribute等。distribute是setuptools的替代品,是對標準庫disutils模組的增強,我們知道disutils主要是用來更加容易的打包和分發包,特別是對其他的包有依賴的包。distribute被建立是因為Setuptools包不再維護了。而pip是easy_install的替代品。

二、安裝pip

# apt-get install python-pip

升級:

# pip install -U pip

三、pip包管理

安裝包:

[email protected]:~# pip install djangoCollecting django  Using cached Django-1.9.5-py2.py3-none-any.whlInstalling collected packages: djangoSuccessfully installed django-1.9.5

指定安裝的軟體包版本:

通過使用==, >=, <=, >, <來指定一個版本號碼。

[email protected]:~# pip install markdown==2.0

升級包:

升級包到當前最新的版本,可以使用-U 或者 --upgrade

# pip install -U django

搜尋包:

# pip search "django"

列出已安裝的包:

[email protected]:~# pip freezeDjango==1.9.5Markdown==2.0

卸載包:

# pip uninstall djang

四、Requirements Format

pip freeze 和pip list兩者都是列出已經安裝的軟體包,有什麼區別呢。help出的解釋如下:

freeze                  Output installed packages in requirements format.list                    List installed packages.

當我們用virtualenv的時候,可以指定一個requirements.txt檔案來解決依賴關係,用法如下:

# pip install -r requirements.txt

requirements.txt有一個固定的格式:軟體包名==版本號碼,每行代表一個軟體包。這樣pip才能理解,如下:

feedparser==5.1.3wsgiref==0.1.2django==1.4.2...

這就是所謂的”requirements format“;我們可以用pip freeze > requirements.txt,匯出到檔案裡,然後在另一個地方pip install -r requirements.txt 再匯入。

兩者的區別可以理解為:pip list列出了所有的包,pip freeze 只列出由pip 安裝的軟體包,並輸出成requirements format格式。


本文出自 “Jason'blog” 部落格,請務必保留此出處http://xujunxian.blog.51cto.com/8614409/1769424

pip介紹與使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.