Python使用PyPI管理組件__Python

來源:互聯網
上載者:User

原文地址:http://www.omgdba.com/python-use-pypi-manage-packages.html

PyPI(Python Pakkage Index,http://pypi.python.org/pypi)是一個Python的公用資產庫,它管理者Python相關的哥哥功能包。任何人都可以登入該首頁去下載Python的相關包資源。當然,為了方便起見,它也提供一個名叫pip的軟體來和easy_install配合來管理組件資源,只用簡單的命令就可以對包進行安裝、更新以及刪除包。

1. pip的安裝

pip可正常工作在Windows、Mac OS、Unix/Linux等作業系統上,但是需要至少2.6+和3.2+的CPython或PyPy的支援。

python 2.7.9 和3.4以後的版本已經內建累pip程式,所以不需要安裝。其他的版本可以使用以下命令進行安裝:

1 2 3 4 5 6 #下載 https : / / bootstrap .pypa .io / get - pip .py #安裝(Linux下需要管理員權限) python get - pip .py #加入環境變數(Windows) #將C:\Python27\Scripts加入PATH

更多的安裝方法請參照:https://pip.pypa.io/en/latest/installing.html

2. pip的使用

1 2 3 4 5 6 7 8 #安裝包 $ pip install SomePackage              # 最新版本 $ pip install SomePackage == 1.0.4      # 指定版本 $ pip install 'SomePackage>=1.0.4'      # 最小版本 #更新包 $ pip install - U SamePackage #刪除包 $ pip uninstall SomePackage

3. 使用第三方源進行更新

因為某些網路原因,在串連pip官網的時候狀況不是很穩定。幸好有很多鏡像站可以使用。我們可以用鏡像站加速下載。鏡像站列表:http://www.pypi-mirrors.org/

使用鏡像源很簡單,用-i指定就行了:
easy_install -i http://pypi.douban.com/simple/ gevent
pip install -i http://pypi.douban.com/simple/ gevent

如果覺得太麻煩,可以配製成預設:
linux下,修改~/.pip/pip.conf,如果沒這檔案則建立。
windows下,修改%HOMEPATH%\pip\pip.ini。
內容為:
[global]
index-url = http://pypi.douban.com/simple

新的版本中會在非https傳輸的鏡像站上報出如下錯誤:

This repository located at mirrors.aliyun.com is not a trusted host, if this repository is available via HTTPS it is recommend to use HTTPS instead, otherwise you may silence this warning with ‘–trusted-host mirrors.aliyun.com’.
DEPRECATION: Implicitly allowing locations which are not hosted at a secure origin is deprecated and will require the use of –trusted-host in the future.
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages

解決辦法就是:

1 2 3 [ global ] trusted

聯繫我們

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