python的pip管理工具,pythonpip管理工具,Python有两个著


Python有两个著名的包管理工具easy_install.py和pip。在Python2.7的安装包中,easy_install.py是默认安装的,而pip需要我们手动安装。

在此进行编译安装pip管理工具,下载地址:https://pypi.org/project/pip/#files

现在的pip版本是pip-10.0.1,支持python2.x和python3.x

1、下载文件,然后解压

tar -xf pip-10.0.1.tar.gz 

2、查看pip文件内容

1 [[email protected] pip-10.0.1]# ls2 AUTHORS.txt  dist  LICENSE.txt  NEWS.rst  pyproject.toml  setup.cfg  src3 build        docs  MANIFEST.in  PKG-INFO  README.rst      setup.py

3、安装pip

[[email protected] pip-10.0.1]# python setup.py install

4、查看pip安装成功版本

1 [[email protected] pip-10.0.1]# pip -V2 pip 10.0.1 from /usr/lib/python2.7/site-packages/pip-10.0.1-py2.7.egg/pip (python 2.7)

5、测试安装psutil模块

[[email protected] ~]# pip install psutil

出现以下问题

 1 Collecting psutil 2   Downloading https://files.pythonhosted.org/packages/51/9e/0f8f5423ce28c9109807024f7bdde776ed0b1161de20b408875de7e030c3/psutil-5.4.6.tar.gz (418kB) 3     100% |████████████████████████████████| 419kB 227kB/s  4 ipaclient 4.5.4 requires jinja2, which is not installed. 5 rtslib-fb 2.1.63 has requirement pyudev>=0.16.1, but you‘ll have pyudev 0.15 which is incompatible. 6 ipapython 4.5.4 has requirement dnspython>=1.15, but you‘ll have dnspython 1.12.0 which is incompatible. 7 Installing collected packages: psutil 8   Running setup.py install for psutil ... error 9     Complete output from command /bin/python -u -c "import setuptools, tokenize;__file__=‘/tmp/pip-install-BO0YvS/psutil/setup.py‘;f=getattr(tokenize, ‘open‘, open)(__file__);code=f.read().replace(‘\r\n‘, ‘\n‘);f.close();exec(compile(code, __file__, ‘exec‘))" install --record /tmp/pip-record-FbEPxr/install-record.txt --single-version-externally-managed --compile:10     /usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘python_requires‘11       warnings.warn(msg)12     running install13     running build14     running build_py15     creating build16     creating build/lib.linux-x86_64-2.717     creating build/lib.linux-x86_64-2.7/psutil18     copying psutil/_exceptions.py -> build/lib.linux-x86_64-2.7/psutil19     copying psutil/_psposix.py -> build/lib.linux-x86_64-2.7/psutil20     copying psutil/_psbsd.py -> build/lib.linux-x86_64-2.7/psutil21     copying psutil/_psaix.py -> build/lib.linux-x86_64-2.7/psutil22     copying psutil/_pssunos.py -> build/lib.linux-x86_64-2.7/psutil23     copying psutil/_pslinux.py -> build/lib.linux-x86_64-2.7/psutil24     copying psutil/_common.py -> build/lib.linux-x86_64-2.7/psutil25     copying psutil/__init__.py -> build/lib.linux-x86_64-2.7/psutil26     copying psutil/_psosx.py -> build/lib.linux-x86_64-2.7/psutil27     copying psutil/_compat.py -> build/lib.linux-x86_64-2.7/psutil28     copying psutil/_pswindows.py -> build/lib.linux-x86_64-2.7/psutil29     creating build/lib.linux-x86_64-2.7/psutil/tests30     copying psutil/tests/__main__.py -> build/lib.linux-x86_64-2.7/psutil/tests31     copying psutil/tests/test_bsd.py -> build/lib.linux-x86_64-2.7/psutil/tests32     copying psutil/tests/test_contracts.py -> build/lib.linux-x86_64-2.7/psutil/tests33     copying psutil/tests/test_aix.py -> build/lib.linux-x86_64-2.7/psutil/tests34     copying psutil/tests/test_memory_leaks.py -> build/lib.linux-x86_64-2.7/psutil/tests35     copying psutil/tests/test_connections.py -> build/lib.linux-x86_64-2.7/psutil/tests36     copying psutil/tests/test_system.py -> build/lib.linux-x86_64-2.7/psutil/tests37     copying psutil/tests/test_linux.py -> build/lib.linux-x86_64-2.7/psutil/tests38     copying psutil/tests/test_misc.py -> build/lib.linux-x86_64-2.7/psutil/tests39     copying psutil/tests/__init__.py -> build/lib.linux-x86_64-2.7/psutil/tests40     copying psutil/tests/test_osx.py -> build/lib.linux-x86_64-2.7/psutil/tests41     copying psutil/tests/test_process.py -> build/lib.linux-x86_64-2.7/psutil/tests42     copying psutil/tests/test_windows.py -> build/lib.linux-x86_64-2.7/psutil/tests43     copying psutil/tests/test_posix.py -> build/lib.linux-x86_64-2.7/psutil/tests44     copying psutil/tests/test_sunos.py -> build/lib.linux-x86_64-2.7/psutil/tests45     copying psutil/tests/test_unicode.py -> build/lib.linux-x86_64-2.7/psutil/tests46     running build_ext47     building ‘psutil._psutil_linux‘ extension48     creating build/temp.linux-x86_64-2.749     creating build/temp.linux-x86_64-2.7/psutil50     gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=546 -DPSUTIL_LINUX=1 -I/usr/include/python2.7 -c psutil/_psutil_common.c -o build/temp.linux-x86_64-2.7/psutil/_psutil_common.o51     psutil/_psutil_common.c:9:20: 致命错误:Python.h:没有那个文件或目录52      #include <Python.h>53                         ^54     编译中断。55     error: command ‘gcc‘ failed with exit status 156     57     ----------------------------------------58 Command "/bin/python -u -c "import setuptools, tokenize;__file__=‘/tmp/pip-install-BO0YvS/psutil/setup.py‘;f=getattr(tokenize, ‘open‘, open)(__file__);code=f.read().replace(‘\r\n‘, ‘\n‘);f.close();exec(compile(code, __file__, ‘exec‘))" install --record /tmp/pip-record-FbEPxr/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-BO0YvS/psutil/

解决方法:

安装python-devel,这是python的头文件和静态库包

[[email protected] ~]# yum install python-devel

6、再次安装psutil模块

1 [[email protected] ~]# pip install psutil      2 Collecting psutil3   Using cached https://files.pythonhosted.org/packages/51/9e/0f8f5423ce28c9109807024f7bdde776ed0b1161de20b408875de7e030c3/psutil-5.4.6.tar.gz4 ipaclient 4.5.4 requires jinja2, which is not installed.5 rtslib-fb 2.1.63 has requirement pyudev>=0.16.1, but you‘ll have pyudev 0.15 which is incompatible.6 ipapython 4.5.4 has requirement dnspython>=1.15, but you‘ll have dnspython 1.12.0 which is incompatible.7 Installing collected packages: psutil8   Running setup.py install for psutil ... done9 Successfully installed psutil-5.4.6

致此,pip安装成功,可以安装自已想要的模块,解决模块的依赖关系。

python的pip管理工具

评论关闭