pip都是用来下载安装Python一个公共资源库PyPI的相关资源包的(简单来说, pip 是一个安装和管理 Python 包的工具),常用的文档eg:https://pip.pypa.io/en/latest/installing/#installing-with-get-pip-py


 (一)pip的下载和安装:

(1)安装pip之前先安装setuptools-0.6c11工具

1
2
3
4
5
[root@KVM pip-1.5.4] #wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
[root@KVM pip-1.5.4] #tar zxvf setuptools-0.6c11.tar.gz
[root@KVM pip-1.5.4] #cd setuptools-0.6c11
[root@KVM pip-1.5.4] #python setup.py build
[root@KVM pip-1.5.4] #python setup.py install

 (2)下载安装pip

1
2
3
4
[root@KVM pip-1.5.4] #wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate
[root@KVM pip-1.5.4] #tar zxvf pip-1.5.4.tar.gz 
[root@KVM pip-1.5.4] #cd pip-1.5.4
[root@KVM pip-1.5.4] # python setup.py install

 (二)pip使用详解:

 (1)使用pip安装包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@KVM ~] # pip install simplejson
Downloading /unpacking  simplejson
   Downloading simplejson-3.8.2. tar .gz (76kB): 76kB downloaded
   Running setup.py (path: /tmp/pip_build_root/simplejson/setup .py) egg_info  for  package simplejson
Installing collected packages: simplejson
   Running setup.py  install  for  simplejson
     building  'simplejson._speedups'  extension
     gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I /usr/include/python2 .6 -c simplejson /_speedups .c -o build /temp .linux-x86_64-2.6 /simplejson/_speedups .o
     simplejson /_speedups .c:2:20: error: Python.h: No such  file  or directory
     simplejson /_speedups .c:3:26: error: structmember.h: No such  file  or directory
         simplejson /_speedups .c: In  function  ‘init_speedups’:
     simplejson /_speedups .c:3391: warning: implicit declaration of  function  ‘moduleinit’
     ***************************************************************************
     WARNING: The C extension could not be compiled, speedups are not enabled.
     Failure information,  if  any, is above.
     I'm retrying the build without the C extension now.
     ***************************************************************************
     ***************************************************************************
     WARNING: The C extension could not be compiled, speedups are not enabled.
     Plain-Python installation succeeded.
     ***************************************************************************
Successfully installed simplejson
Cleaning up...


 (2)安装特定的版本及升级:安装特定版本的package,通过使用==, >=, <=, >, <来指定一个版本号。

pip install 'Markdown<2.0' 或 pip install 'Markdown>2.0,<2.0.3'

升级包到当前最新的版本,可以使用-U 或者 --upgradepip install -U Markdown

卸载包pip uninstall Markdown

查询包:pip search "multiprocessing"

列出安装的packages:pip freeze

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
[root@KVM pip-1.5.4] # pip install -U Markdown        ######升级包markdown
Requirement already up-to- date : Markdown  in  /usr/lib/python2 .6 /site-packages
Cleaning up...
[root@KVM pip-1.5.4] # pipuninstall markdown
- bash : pipuninstall:  command  not found
[root@KVM pip-1.5.4] # pip uninstall markdown          ######卸载包
Uninstalling Markdown:
   /usr/bin/markdown_py
   /usr/lib/python2 .6 /site-packages/Markdown-2 .6.5-py2.6.egg-info
   /usr/lib/python2 .6 /site-packages/markdown/__init__ .py
Proceed (y /n )? y
   Successfully uninstalled Markdown
[root@KVM pip-1.5.4] # pip install markdown            ######安装包
Downloading /unpacking  markdown
   Downloading Markdown-2.6.5. tar .gz (301kB): 301kB downloaded
   Running setup.py (path: /tmp/pip_build_root/markdown/setup .py) egg_info  for  package markdown
Installing collected packages: markdown
   Running setup.py  install  for  markdown
     changing mode of build /scripts-2 .6 /markdown_py  from 644 to 755
     skipping build_docs: Markdown  "import"  failed!
     changing mode of  /usr/bin/markdown_py  to 755
Successfully installed markdown
Cleaning up...
[root@KVM pip-1.5.4] # pip search "markdown"               ######查询包
notedown                  - Convert markdown to IPython notebook.
cmddocs                   - An interactive commandline interface  for  your personal docs using python,
                             Cmd, git and markdown
understate                - markdown presentations using ncurses
markdown-attr-plus        - Markdown Extension to extend attr_list extension to add extra syntax.
mdx_twitchmoticons        - Python-Markdown extension to support Twitch.tv-style emoticons.
markdown2Mathjax          - Extend markdown2  for  use with mathjax
pelican                   - A tool to generate a static blog from reStructuredText or Markdown input
                             files.
markdownify               - Convert HTML to markdown.
[root@KVM pip-1.5.4] # pip freeze                              #######列出已安装的包
Markdown==2.6.5
argparse==1.2.1
elasticsearch==2.3.0
ethtool ==0.6
firstboot==1.110
glusterfs-api==3.6.0.54
iniparse==0.3.1
pycurl==7.19.0
pygpgme==0.1
python-meh==0.11
pyxdg==0.18
scdate==1.9.60
simplejson==3.8.2
slip==0.2.20
urlgrabber==3.9.1
urllib3==1.14
virtinst==0.600.0
yum-metadata-parser==1.1.2


   


备注:常用的命令如下:

1,pip show --files somepackage  ------查看已安装的包

2,pip list --outdated        -------检查那些包需要更新

3,pip install --upgrage somepackage  --------升级somepackage包

4,pip uninstall somepackage     -------pip卸载包

5,pip --help  ------查看帮助信息