python的pip管理工具

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 [root@python pip-10.0.1]# ls
2 AUTHORS.txt  dist  LICENSE.txt  NEWS.rst  pyproject.toml  setup.cfg  src
3 build        docs  MANIFEST.in  PKG-INFO  README.rst      setup.py

3、安装pip

[root@python pip-10.0.1]# python setup.py install

4、查看pip安装成功版本

1 [root@python pip-10.0.1]# pip -V
2 pip 10.0.1 from /usr/lib/python2.7/site-packages/pip-10.0.1-py2.7.egg/pip (python 2.7)

5、测试安装psutil模块

[root@python ~]# 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 install
13     running build
14     running build_py
15     creating build
16     creating build/lib.linux-x86_64-2.7
17     creating build/lib.linux-x86_64-2.7/psutil
18     copying psutil/_exceptions.py -> build/lib.linux-x86_64-2.7/psutil
19     copying psutil/_psposix.py -> build/lib.linux-x86_64-2.7/psutil
20     copying psutil/_psbsd.py -> build/lib.linux-x86_64-2.7/psutil
21     copying psutil/_psaix.py -> build/lib.linux-x86_64-2.7/psutil
22     copying psutil/_pssunos.py -> build/lib.linux-x86_64-2.7/psutil
23     copying psutil/_pslinux.py -> build/lib.linux-x86_64-2.7/psutil
24     copying psutil/_common.py -> build/lib.linux-x86_64-2.7/psutil
25     copying psutil/__init__.py -> build/lib.linux-x86_64-2.7/psutil
26     copying psutil/_psosx.py -> build/lib.linux-x86_64-2.7/psutil
27     copying psutil/_compat.py -> build/lib.linux-x86_64-2.7/psutil
28     copying psutil/_pswindows.py -> build/lib.linux-x86_64-2.7/psutil
29     creating build/lib.linux-x86_64-2.7/psutil/tests
30     copying psutil/tests/__main__.py -> build/lib.linux-x86_64-2.7/psutil/tests
31     copying psutil/tests/test_bsd.py -> build/lib.linux-x86_64-2.7/psutil/tests
32     copying psutil/tests/test_contracts.py -> build/lib.linux-x86_64-2.7/psutil/tests
33     copying psutil/tests/test_aix.py -> build/lib.linux-x86_64-2.7/psutil/tests
34     copying psutil/tests/test_memory_leaks.py -> build/lib.linux-x86_64-2.7/psutil/tests
35     copying psutil/tests/test_connections.py -> build/lib.linux-x86_64-2.7/psutil/tests
36     copying psutil/tests/test_system.py -> build/lib.linux-x86_64-2.7/psutil/tests
37     copying psutil/tests/test_linux.py -> build/lib.linux-x86_64-2.7/psutil/tests
38     copying psutil/tests/test_misc.py -> build/lib.linux-x86_64-2.7/psutil/tests
39     copying psutil/tests/__init__.py -> build/lib.linux-x86_64-2.7/psutil/tests
40     copying psutil/tests/test_osx.py -> build/lib.linux-x86_64-2.7/psutil/tests
41     copying psutil/tests/test_process.py -> build/lib.linux-x86_64-2.7/psutil/tests
42     copying psutil/tests/test_windows.py -> build/lib.linux-x86_64-2.7/psutil/tests
43     copying psutil/tests/test_posix.py -> build/lib.linux-x86_64-2.7/psutil/tests
44     copying psutil/tests/test_sunos.py -> build/lib.linux-x86_64-2.7/psutil/tests
45     copying psutil/tests/test_unicode.py -> build/lib.linux-x86_64-2.7/psutil/tests
46     running build_ext
47     building 'psutil._psutil_linux' extension
48     creating build/temp.linux-x86_64-2.7
49     creating build/temp.linux-x86_64-2.7/psutil
50     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.o
51     psutil/_psutil_common.c:9:20: 致命错误:Python.h:没有那个文件或目录
52      #include <Python.h>
53                         ^
54     编译中断。
55     error: command 'gcc' failed with exit status 1
56     
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的头文件和静态库包

[root@python ~]# yum install python-devel

6、再次安装psutil模块

1 [root@python ~]# pip install psutil      
2 Collecting psutil
3   Using cached https://files.pythonhosted.org/packages/51/9e/0f8f5423ce28c9109807024f7bdde776ed0b1161de20b408875de7e030c3/psutil-5.4.6.tar.gz
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 ... done
9 Successfully installed psutil-5.4.6

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

猜你喜欢

转载自www.cnblogs.com/eeexu123/p/9290994.html