Python有很多第三方的模块或包,要管理这些包,有很多方法。python的pip包管理工具,类似与CentOS中yum,使用该工具安装Python包非常方便。
从Python内部来说,pip 是一个安装和管理 Python 包的工具 , 是 easy_install 的一个替换品。
distribute是setuptools的取代(Setuptools包后期不再维护了),pip是easy_install的取代。
pip的安装前需要setuptools 或者 distribute,如果你使用的是Python3.x那么就只能使用distribute因为Python3.x不支持setuptools。
我的CentOS环境是Python 2.6,所以在之前已经按照好了setuptools,安装下面的步骤安装pip包管理工具。
1.pip工具的下载安装
pip下载命令为:
# cd /usr/local/src --路径可以根据情况修改 # wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate
pip 安装命令为:
# tar -xzvf pip-1.5.4.tar.gz # cd pip-1.5.4 # python setup.py install
2.pip工具使用方法
pip安装一个包 # pip install SomePackage [...] Successfully installed SomePackage pip列出已经安装的包 # pip list pip查看已经安装的包 # pip show --files SomePackage Name: SomePackage Version: 1.0 Location: /my/env/lib/pythonx.x/site-packages Files: ../somepackage/__init__.py [...] pip检查哪些包需要更新 # pip list --outdated SomePackage (Current: 1.0 Latest: 2.0) pip升级包 # pip install --upgrade SomePackage [...] Found existing installation: SomePackage 1.0 Uninstalling SomePackage: Successfully uninstalled SomePackage Running setup.py install for SomePackage Successfully installed SomePackage pip卸载包 $ pip uninstall SomePackage Uninstalling SomePackage: /my/env/lib/pythonx.x/site-packages/somepackage Proceed (y/n)? y Successfully uninstalled SomePackage
3.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:[email protected]]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> 证书.
4.pip管理包实际执行过程:
#使用pip 安装Python操作Excel的模块 XlsxWriter # pip install XlsxWriter Downloading/unpacking XlsxWriter Downloading XlsxWriter-0.7.3-py2.py3-none-any.whl (132kB): 132kB downloaded Installing collected packages: XlsxWriter Successfully installed XlsxWriter Cleaning up... [[email protected] pip-1.5.4]# [[email protected] pip-1.5.4]# pip list Beaker (1.3.1) cas (0.15) decorator (3.0.1) distribute (0.6.10) ethtool (0.6) firstboot (1.110) FormEncode (1.3.0) freeipa (2.0.0.alpha.0) iniparse (0.3.1) iotop (0.3.2) ipapython (3.0.0) iwlib (1.0) kerberos (1.0) lxml (2.2.3) Mako (0.3.4) MarkupSafe (0.9.2) matplotlib (0.99.1.1) netaddr (0.7.5) nose (0.10.4) numpy (1.4.1) ordereddict (1.2) paramiko (1.7.5) pip (1.5.4) psutil (2.0.0) pycrypto (2.0.1) pycurl (7.19.0) PyDispatcher (2.0.5) pygpgme (0.1) pyOpenSSL (0.10) python-dateutil (1.4.1) python-default-encoding (0.1) python-ldap (2.3.10) python-meh (0.11) python-nss (0.13) pytz (2010h) pyxdg (0.18) scdate (1.9.60) sckdump (2.0.5) scservices (0.99.45) scservices.dbus (0.99.45) setuptools (18.2) slip (0.2.20) slip.dbus (0.2.20) slip.gtk (0.2.20) Warning: cannot find svn location for SQLObject==3.0.0a1dev-20150327 SQLObject (3.0.0a1dev-20150327) SSSDConfig (1.9.2) urlgrabber (3.9.1) XlsxWriter (0.7.3) yum-metadata-parser (1.1.2) # #使用pip 显示Python操作Excel的模块 XlsxWriter # pip show --files XlsxWriter --- Name: XlsxWriter Version: 0.7.3 Location: /usr/lib/python2.6/site-packages Requires: Files: Cannot locate installed-files.txt # #使用pip 显示已经安装的Python的包 # pip list Beaker (1.3.1) cas (0.15) decorator (3.0.1) distribute (0.6.10) ethtool (0.6) firstboot (1.110) FormEncode (1.3.0) freeipa (2.0.0.alpha.0) iniparse (0.3.1) iotop (0.3.2) ipapython (3.0.0) iwlib (1.0) kerberos (1.0) lxml (2.2.3) Mako (0.3.4) MarkupSafe (0.9.2) matplotlib (0.99.1.1) netaddr (0.7.5) nose (0.10.4) numpy (1.4.1) ordereddict (1.2) paramiko (1.7.5) pip (1.5.4) psutil (2.0.0) pycrypto (2.0.1) pycurl (7.19.0) PyDispatcher (2.0.5) pygpgme (0.1) pyOpenSSL (0.10) python-dateutil (1.4.1) python-default-encoding (0.1) python-ldap (2.3.10) python-meh (0.11) python-nss (0.13) pytz (2010h) pyxdg (0.18) scdate (1.9.60) sckdump (2.0.5) scservices (0.99.45) scservices.dbus (0.99.45) setuptools (18.2) slip (0.2.20) slip.dbus (0.2.20) slip.gtk (0.2.20) Warning: cannot find svn location for SQLObject==3.0.0a1dev-20150327 SQLObject (3.0.0a1dev-20150327) SSSDConfig (1.9.2) urlgrabber (3.9.1) yum-metadata-parser (1.1.2) [[email protected] pip-1.5.4] #使用pip 显示需要更新的包 # pip list --outdated Warning: cannot find svn location for SQLObject==3.0.0a1dev-20150327 psutil (Current: 2.0.0 Latest: 3.1.1) pip (Current: 1.5.4 Latest: 7.1.2) matplotlib (Current: 0.99.1.1 Latest: 1.4.3) iwlib (Current: 1.0 Latest: 1.5) pycrypto (Current: 2.0.1 Latest: 2.6.1) pyOpenSSL (Current: 0.10 Latest: 0.15.1) Could not find any downloads that satisfy the requirement python-default-encoding Some externally hosted files were ignored (use --allow-external python-default-encoding to allow). python-nss (Current: 0.13 Latest: 0.16.0) MarkupSafe (Current: 0.9.2 Latest: 0.23) lxml (Current: 2.2.3 Latest: 3.4.4) pygpgme (Current: 0.1 Latest: 0.3) pycurl (Current: 7.19.0 Latest: 7.19.5.1) Could not find any downloads that satisfy the requirement ethtool Some externally hosted files were ignored (use --allow-external ethtool to allow). numpy (Current: 1.4.1 Latest: 1.9.2) kerberos (Current: 1.0 Latest: 1.2.2) Could not find any downloads that satisfy the requirement yum-metadata-parser Some externally hosted files were ignored (use --allow-external yum-metadata-parser to allow). python-ldap (Current: 2.3.10 Latest: 2.4.20) Could not find any downloads that satisfy the requirement sckdump Some externally hosted files were ignored (use --allow-external sckdump to allow). Could not find any downloads that satisfy the requirement ipapython Some externally hosted files were ignored (use --allow-external ipapython to allow). Could not find any downloads that satisfy the requirement slip.gtk Some externally hosted files were ignored (use --allow-external slip.gtk to allow). Could not find any downloads that satisfy the requirement firstboot Some externally hosted files were ignored (use --allow-external firstboot to allow). Could not find any downloads that satisfy the requirement scdate Some externally hosted files were ignored (use --allow-external scdate to allow). Mako (Current: 0.3.4 Latest: 1.0.2) Beaker (Current: 1.3.1 Latest: 1.7.0) cas (Current: 0.15 Latest: 1.22) distribute (Current: 0.6.10 Latest: 0.7.3) Could not find any downloads that satisfy the requirement scservices.dbus Some externally hosted files were ignored (use --allow-external scservices.dbus to allow). python-dateutil (Current: 1.4.1 Latest: 2.4.2) Could not find any downloads that satisfy the requirement sssdconfig Some externally hosted files were ignored (use --allow-external sssdconfig to allow). decorator (Current: 3.0.1 Latest: 4.0.2) nose (Current: 0.10.4 Latest: 1.3.7) Could not find any downloads that satisfy the requirement freeipa Some externally hosted files were ignored (use --allow-external freeipa to allow). iniparse (Current: 0.3.1 Latest: 0.4) Could not find any downloads that satisfy the requirement slip.dbus Some externally hosted files were ignored (use --allow-external slip.dbus to allow). netaddr (Current: 0.7.5 Latest: 0.7.15) paramiko (Current: 1.7.5 Latest: 1.15.2) Could not find any downloads that satisfy the requirement python-meh Some externally hosted files were ignored (use --allow-external python-meh to allow). pytz (Current: 2010h Latest: 2015.4) Could not find any downloads that satisfy the requirement scservices Some externally hosted files were ignored (use --allow-external scservices to allow). Could not find any downloads that satisfy the requirement iotop Some externally hosted files were ignored (use --allow-external iotop to allow). pyxdg (Current: 0.18 Latest: 0.25) # #使用pip 升级psutil模块 # pip install --upgrade psutil Downloading/unpacking psutil from https://pypi.python.org/packages/source/p/psutil/psutil-3.1.1.tar.gz#md5=b34360627efb429cb18a4a3143b18c8c Downloading psutil-3.1.1.tar.gz (247kB): 247kB downloaded Running setup.py (path:/tmp/pip_build_root/psutil/setup.py) egg_info for package psutil /tmp/pip_build_root/psutil/setup.py:12: DeprecationWarning: Parameters to load are deprecated. Call .resolve and .require separately. import os warning: no previously-included files matching ‘*‘ found under directory ‘docs/_build‘ warning: manifest_maker: MANIFEST.in, line 18: ‘recursive-include‘ expects <dir> <pattern1> <pattern2> ... Installing collected packages: psutil Found existing installation: psutil 2.0.0 Uninstalling psutil: Successfully uninstalled psutil Running setup.py install for psutil building ‘psutil._psutil_linux‘ 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 -DPSUTIL_VERSION=311 -I/usr/include/python2.6 -c psutil/_psutil_linux.c -o build/temp.linux-x86_64-2.6/psutil/_psutil_linux.o psutil/_psutil_linux.c: In function ‘psutil_proc_cpu_affinity_set’: psutil/_psutil_linux.c:420: warning: suggest explicit braces to avoid ambiguous ‘else’ gcc -pthread -shared build/temp.linux-x86_64-2.6/psutil/_psutil_linux.o -L/usr/lib64 -lpython2.6 -o build/lib.linux-x86_64-2.6/psutil/_psutil_linux.so building ‘psutil._psutil_posix‘ 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 psutil/_psutil_posix.c -o build/temp.linux-x86_64-2.6/psutil/_psutil_posix.o gcc -pthread -shared build/temp.linux-x86_64-2.6/psutil/_psutil_posix.o -L/usr/lib64 -lpython2.6 -o build/lib.linux-x86_64-2.6/psutil/_psutil_posix.so warning: no previously-included files matching ‘*‘ found under directory ‘docs/_build‘ warning: manifest_maker: MANIFEST.in, line 18: ‘recursive-include‘ expects <dir> <pattern1> <pattern2> ... Successfully installed psutil Cleaning up... #使用pip 卸载Python操作Excel的模块 XlsxWriter [[email protected] pip-1.5.4]# pip uninstall XlsxWriter Uninstalling XlsxWriter: /usr/bin/vba_extract.py /usr/bin/vba_extract.pyc /usr/lib/python2.6/site-packages/XlsxWriter-0.7.3.dist-info/DESCRIPTION.rst /usr/lib/python2.6/site-packages/XlsxWriter-0.7.3.dist-info/METADATA /usr/lib/python2.6/site-packages/XlsxWriter-0.7.3.dist-info/RECORD /usr/lib/python2.6/site-packages/XlsxWriter-0.7.3.dist-info/WHEEL /usr/lib/python2.6/site-packages/XlsxWriter-0.7.3.dist-info/metadata.json /usr/lib/python2.6/site-packages/XlsxWriter-0.7.3.dist-info/top_level.txt /usr/lib/python2.6/site-packages/xlsxwriter/__init__.py /usr/lib/python2.6/site-packages/xlsxwriter/__init__.pyc /usr/lib/python2.6/site-packages/xlsxwriter/app.py /usr/lib/python2.6/site-packages/xlsxwriter/app.pyc /usr/lib/python2.6/site-packages/xlsxwriter/chart.py /usr/lib/python2.6/site-packages/xlsxwriter/chart.pyc /usr/lib/python2.6/site-packages/xlsxwriter/chart_area.py /usr/lib/python2.6/site-packages/xlsxwriter/chart_area.pyc /usr/lib/python2.6/site-packages/xlsxwriter/chart_bar.py /usr/lib/python2.6/site-packages/xlsxwriter/chart_bar.pyc /usr/lib/python2.6/site-packages/xlsxwriter/chart_column.py /usr/lib/python2.6/site-packages/xlsxwriter/chart_column.pyc /usr/lib/python2.6/site-packages/xlsxwriter/chart_doughnut.py /usr/lib/python2.6/site-packages/xlsxwriter/chart_doughnut.pyc /usr/lib/python2.6/site-packages/xlsxwriter/chart_line.py /usr/lib/python2.6/site-packages/xlsxwriter/chart_line.pyc /usr/lib/python2.6/site-packages/xlsxwriter/chart_pie.py /usr/lib/python2.6/site-packages/xlsxwriter/chart_pie.pyc /usr/lib/python2.6/site-packages/xlsxwriter/chart_radar.py /usr/lib/python2.6/site-packages/xlsxwriter/chart_radar.pyc /usr/lib/python2.6/site-packages/xlsxwriter/chart_scatter.py /usr/lib/python2.6/site-packages/xlsxwriter/chart_scatter.pyc /usr/lib/python2.6/site-packages/xlsxwriter/chart_stock.py /usr/lib/python2.6/site-packages/xlsxwriter/chart_stock.pyc /usr/lib/python2.6/site-packages/xlsxwriter/chartsheet.py /usr/lib/python2.6/site-packages/xlsxwriter/chartsheet.pyc /usr/lib/python2.6/site-packages/xlsxwriter/comments.py /usr/lib/python2.6/site-packages/xlsxwriter/comments.pyc /usr/lib/python2.6/site-packages/xlsxwriter/compat_collections.py /usr/lib/python2.6/site-packages/xlsxwriter/compat_collections.pyc /usr/lib/python2.6/site-packages/xlsxwriter/compatibility.py /usr/lib/python2.6/site-packages/xlsxwriter/compatibility.pyc /usr/lib/python2.6/site-packages/xlsxwriter/contenttypes.py /usr/lib/python2.6/site-packages/xlsxwriter/contenttypes.pyc /usr/lib/python2.6/site-packages/xlsxwriter/core.py /usr/lib/python2.6/site-packages/xlsxwriter/core.pyc /usr/lib/python2.6/site-packages/xlsxwriter/drawing.py /usr/lib/python2.6/site-packages/xlsxwriter/drawing.pyc /usr/lib/python2.6/site-packages/xlsxwriter/format.py /usr/lib/python2.6/site-packages/xlsxwriter/format.pyc /usr/lib/python2.6/site-packages/xlsxwriter/packager.py /usr/lib/python2.6/site-packages/xlsxwriter/packager.pyc /usr/lib/python2.6/site-packages/xlsxwriter/relationships.py /usr/lib/python2.6/site-packages/xlsxwriter/relationships.pyc /usr/lib/python2.6/site-packages/xlsxwriter/shape.py /usr/lib/python2.6/site-packages/xlsxwriter/shape.pyc /usr/lib/python2.6/site-packages/xlsxwriter/sharedstrings.py /usr/lib/python2.6/site-packages/xlsxwriter/sharedstrings.pyc /usr/lib/python2.6/site-packages/xlsxwriter/styles.py /usr/lib/python2.6/site-packages/xlsxwriter/styles.pyc /usr/lib/python2.6/site-packages/xlsxwriter/table.py /usr/lib/python2.6/site-packages/xlsxwriter/table.pyc /usr/lib/python2.6/site-packages/xlsxwriter/theme.py /usr/lib/python2.6/site-packages/xlsxwriter/theme.pyc /usr/lib/python2.6/site-packages/xlsxwriter/utility.py /usr/lib/python2.6/site-packages/xlsxwriter/utility.pyc /usr/lib/python2.6/site-packages/xlsxwriter/vml.py /usr/lib/python2.6/site-packages/xlsxwriter/vml.pyc /usr/lib/python2.6/site-packages/xlsxwriter/workbook.py /usr/lib/python2.6/site-packages/xlsxwriter/workbook.pyc /usr/lib/python2.6/site-packages/xlsxwriter/worksheet.py /usr/lib/python2.6/site-packages/xlsxwriter/worksheet.pyc /usr/lib/python2.6/site-packages/xlsxwriter/xmlwriter.py /usr/lib/python2.6/site-packages/xlsxwriter/xmlwriter.pyc Proceed (y/n)? y Successfully uninstalled XlsxWriter
时间: 2024-10-14 00:18:48