Python:easy_install
Python的使用过程中,我们安装第三方库的常见步骤是这样的:
1. 下载对应第三方库的安装包,它们可能长这个样子:xxx.tar.gz
2. 解压:tar -xzf xxx.tar.gz
3. 进入解压后的根目录,用Python去安装:python setup.py install
这么做比较麻烦,为了让这个过程更简单,Python的setuptools中提供了easy_install的模块,让你可以只需要给出要安装的模块名,它自己就会去Python的官方网站中检索该模块。如果找到,就会下载,并自动安装:
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 54 55 56 57 58 59 |
root@philosopher:~# whereis python python: /usr/bin/python2.7-config /usr/bin/python /usr/bin/python3.4m /usr/bin/python2.7 /usr/bin/python3.4 /usr/lib/python3.5 /usr/lib/python2.7 /usr/lib/python2.6 /usr/lib/python3.4 /etc/python /etc/python3.5 /etc/python2.7 /etc/python3.4 /usr/local/lib/python2.7 /usr/local/lib/python3.4 /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz root@philosopher:~# root@philosopher:~# whereis easy_install easy_install: /usr/bin/easy_install root@philosopher:~# root@philosopher:~# easy_install pyPdf python-nmap pygeoip mechanize BeautifulSoup4 Searching for pyPdf Best match: pyPdf 1.13 Adding pyPdf 1.13 to easy-install.pth file Using /usr/lib/python2.7/dist-packages Processing dependencies for pyPdf Finished processing dependencies for pyPdf Searching for python-nmap Reading https://pypi.python.org/simple/python-nmap/ Best match: python-nmap 0.6.0 Downloading https://pypi.python.org/packages/c6/f9/98a1b0f012b11027e59daf4b1da99215c2e1cc56cf7de7564e8d6a1a7fd8/python-nmap-0.6.0.tar.gz#md5=c3996b1e8dfb944fa30fb37d3fc43a67 Processing python-nmap-0.6.0.tar.gz Writing /tmp/easy_install-n5EplG/python-nmap-0.6.0/setup.cfg Running python-nmap-0.6.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-n5EplG/python-nmap-0.6.0/egg-dist-tmp-gYb1qU /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url' warnings.warn(msg) zip_safe flag not set; analyzing archive contents... Moving python_nmap-0.6.0-py2.7.egg to /usr/local/lib/python2.7/dist-packages Adding python-nmap 0.6.0 to easy-install.pth file Installed /usr/local/lib/python2.7/dist-packages/python_nmap-0.6.0-py2.7.egg Processing dependencies for python-nmap Finished processing dependencies for python-nmap Searching for pygeoip Reading https://pypi.python.org/simple/pygeoip/ Best match: pygeoip 0.3.2 Downloading https://pypi.python.org/packages/ed/65/bb86312b064a6e79c82965202f239850008dbcc9bb24bd0d0bfc7b7bea0b/pygeoip-0.3.2.tar.gz#md5=861664f8be3bed44820356539f2ea5b6 Processing pygeoip-0.3.2.tar.gz Writing /tmp/easy_install-AK3MF1/pygeoip-0.3.2/setup.cfg Running pygeoip-0.3.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-AK3MF1/pygeoip-0.3.2/egg-dist-tmp-7u434H zip_safe flag not set; analyzing archive contents... Moving pygeoip-0.3.2-py2.7.egg to /usr/local/lib/python2.7/dist-packages Adding pygeoip 0.3.2 to easy-install.pth file Installed /usr/local/lib/python2.7/dist-packages/pygeoip-0.3.2-py2.7.egg Processing dependencies for pygeoip Finished processing dependencies for pygeoip Searching for mechanize Best match: mechanize 0.2.5 mechanize 0.2.5 is already the active version in easy-install.pth Using /usr/lib/python2.7/dist-packages Processing dependencies for mechanize Finished processing dependencies for mechanize Searching for BeautifulSoup4 Best match: beautifulsoup4 4.4.1 beautifulsoup4 4.4.1 is already the active version in easy-install.pth Using /usr/lib/python2.7/dist-packages Processing dependencies for BeautifulSoup4 Finished processing dependencies for BeautifulSoup4 root@philosopher:~# |
————————————————
Done。