Python Pip 包管理器

來源: http://blog.csdn.net/olanlanxiari/article/details/48086917


1前言

pip是一個Python包管理工具,主要是用于安裝PyPI上的軟件包,可以替代easy_install工具。

GitHub:https://github.com/pypa/pip

Doc:https://pip.pypa.io/en/latest/

2獲取pip

2.1腳本安裝pip

$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py

$ python get-pip.py

2.2使用包管理軟件安裝

$ sudo yum install python-pip

$ sudo apt-get install python-pip

2.3更新pip

$ pip install -U pip

3pip基本使用

3.1安裝PyPI軟件

$ pip install SomePackage

[...]

Successfully installed SomePackage

3.2查看具體安裝文件

$ pip show --files SomePackage

Name: SomePackage

Version: 1.0

Location: /my/env/lib/pythonx.x/site-packages

Files:

../somepackage/__init__.py

[...]

3.3查看哪些軟件需要更新

$ pip list --outdated

SomePackage (Current: 1.0 Latest: 2.0)

3.4升級軟件包

$ pip install --upgrade SomePackage

[...]

Found existing installation: SomePackage 1.0

Uninstalling SomePackage:

Successfully uninstalled SomePackage

Running setup.py install for SomePackage

Successfully installed SomePackage

3.5卸載軟件包

$ pip uninstall SomePackage

Uninstalling SomePackage:

/my/env/lib/pythonx.x/site-packages/somepackage

Proceed (y/n)? y

Successfully uninstalled SomePackage

4pip簡明手冊

4.1安裝具體版本軟件

$ pip install SomePackage? ? ? ? ? ? # latest version

$ pip install SomePackage==1.0.4? ? # specific version

$ pip install 'SomePackage>=1.0.4'? ? # minimum version

4.2Requirements文件安裝依賴軟件

Requirements文件一般記錄的是依賴軟件列表,通過pip可以一次性安裝依賴軟件包:

$ pip freeze > requirements.txt

$ pip install -r requirements.txt

4.3列出軟件包清單

$ pip list

$ pip list --outdated

ipython (Current: 1.2.0 Latest: 2.3.0)

4.4查看軟件包信息

$ pip show pip

---

Name: pip

Version: 1.4.1

Location: /Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg

Requires:

$ pip show pyopencl

---

Name: pyopencl

Version: 2014.1

Location: /Library/Python/2.7/site-packages

Requires: pytools, pytest, decorator

4.5搜尋

$ pip search pycuda

pycuda? ? ? ? ? ? ? ? ? ? - Python wrapper for Nvidia CUDA

pyfft? ? ? ? ? ? ? ? ? ? - FFT library for PyCuda and PyOpenCL

cudatree? ? ? ? ? ? ? ? ? - Random Forests for the GPU using PyCUDA

reikna? ? ? ? ? ? ? ? ? ? - GPGPU algorithms for PyCUDA and PyOpenCL

compyte? ? ? ? ? ? ? ? ? - A common set of compute primitives for PyCUDA and PyOpenCL (to be created)

4.6配置文件

配置文件:$HOME/.pip/pip.conf, 舉例:

[global]

timeout = 60

index-url = http://download.zope.org/ppix

[install]

ignore-installed = true

no-dependencies = yes

4.7命令行自動補全

對于bash:

$ pip completion --bash >> ~/.profile

對于zsh:

$ pip completion --zsh >> ~/.zprofile

加載此配置文件后,則pip命令支持自動補全功能.

5后記

應該盡量使用pip,不要繼續(xù)使用easy_install.

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容