pip相似RedHat裏面的yum,安裝Python包很是方便。本節詳細介紹pip的安裝、以及使用方法。python
1、pip下載安裝vim
1.1 pip下載python2.7
wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificateui
1.2 pip安裝 日誌
# tar -xzvf pip-1.5.4.tar.gzorm
# cd pip-1.5.4server
# python setup.py installip
1.3 若是pip安裝後提示依然沒有pip命令,需在在添加環境變量md5
# vim /etc/profilessl
在文檔最後,添加:
export PATH="/usr/local/python2.7/bin:$PATH"
保存,退出
而後運行:
#source /etc/profile
2、查看pip版本
pip -V
pip 1.5.4 from /usr/local/python2.7/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg (python 2.7)
3、pip使用詳解
3.1 pip安裝包
pip install paramiko
[...]
Successfully installed paramiko
3.2 pip查看已安裝的包
[root@test1]# pip show --files paramiko
---
Name: paramiko
Version: 1.16.0
Location: /usr/local/python2.7/lib/python2.7/site-packages
Requires: pycrypto, ecdsa
Files:
Cannot locate installed-files.txt
3.3 pip檢查哪些包須要更新
[root@test1 /]# pip list --outdated
setuptools (Current: 0.6c11 Latest: 19.2)
pip (Current: 1.5.4 Latest: 7.1.2)
Django (Current: 1.8.5 Latest: 1.9.1)
3.4 pip升級包
pip install --upgrade Django
3.5 pip卸載包
pip uninstall Django
4、常見錯誤
4.1 ImportError No module named setuptools解決辦法
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install
4.2 ImportError: cannot import name HTTPSHandler解決辦法
yum安裝openssl和openssl-devel,而後從新編譯python
5、pip參數解釋
# pip --help
Usage:
pip <command> [options]
Commands:
install 安裝包.
uninstall 卸載包.
freeze 按着必定格式輸出已安裝包列表
list 列出已安裝包.
show 顯示包詳細信息.
search 搜索包,相似yum裏的search.
wheel Build wheels from your requirements.
zip 不推薦. Zip individual packages.
unzip 不推薦. Unzip individual packages.
bundle 不推薦. Create pybundles.
help 當前幫助.
General Options:
-h, --help 顯示幫助.
-v, --verbose 更多的輸出,最多能夠使用3次
-V, --version 現實版本信息而後退出.
-q, --quiet 最少的輸出.
--log-file <path> 覆蓋的方式記錄verbose錯誤日誌,默認文件:/root/.pip/pip.log
--log <path> 不覆蓋記錄verbose輸出的日誌.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--timeout <sec> 鏈接超時時間 (默認15秒).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
--cert <path> 證書.