在安装Python的psutil模块时,报“error: command 'x86_64-linux-gnu-gcc' failed with exit status 1”的错误,系统提示缺少Python的头文件,那就是说系统没有安装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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
sudo  pip  install  psutil
[ sudo ] password  for  richard: 
Downloading /unpacking  psutil
   Downloading psutil-2.2.1. tar .gz (223kB): 223kB downloaded
   Running setup.py (path: /tmp/pip_build_root/psutil/setup .py) egg_info  for  package psutil
     
     warning: no previously-included files matching  '*'  found under directory  'docs/_build'
Installing collected packages: psutil
   Running setup.py  install  for  psutil
     building  '_psutil_linux'  extension
     x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSUTIL_VERSION=221 -I /usr/include/python2 .7 -c psutil /_psutil_linux .c -o build /temp .linux-x86_64-2.7 /psutil/_psutil_linux .o
     psutil /_psutil_linux .c:12:20: fatal error: Python.h: No such  file  or directory
      #include <Python.h>
                         ^
     compilation terminated.
     error:  command  'x86_64-linux-gnu-gcc'  failed with  exit  status 1
     Complete output from  command  /usr/bin/python  -c  "import setuptools, tokenize;__file__='/tmp/pip_build_root/psutil/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))"  install  --record  /tmp/pip-t0gEEe-record/install-record .txt --single-version-externally-managed --compile:
     running  install
running build
running build_py
creating build
creating build /lib .linux-x86_64-2.7
creating build /lib .linux-x86_64-2.7 /psutil
copying psutil /_psbsd .py -> build /lib .linux-x86_64-2.7 /psutil
copying psutil /_pswindows .py -> build /lib .linux-x86_64-2.7 /psutil
copying psutil /__init__ .py -> build /lib .linux-x86_64-2.7 /psutil
copying psutil /_pslinux .py -> build /lib .linux-x86_64-2.7 /psutil
copying psutil /_pssunos .py -> build /lib .linux-x86_64-2.7 /psutil
copying psutil /_compat .py -> build /lib .linux-x86_64-2.7 /psutil
copying psutil /_common .py -> build /lib .linux-x86_64-2.7 /psutil
copying psutil /_psosx .py -> build /lib .linux-x86_64-2.7 /psutil
copying psutil /_psposix .py -> build /lib .linux-x86_64-2.7 /psutil
running build_ext
building  '_psutil_linux'  extension
creating build /temp .linux-x86_64-2.7
creating build /temp .linux-x86_64-2.7 /psutil
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSUTIL_VERSION=221 -I /usr/include/python2 .7 -c psutil /_psutil_linux .c -o build /temp .linux-x86_64-2.7 /psutil/_psutil_linux .o
psutil /_psutil_linux .c:12:20: fatal error: Python.h: No such  file  or directory
  #include <Python.h>
                     ^
compilation terminated.
error:  command  'x86_64-linux-gnu-gcc'  failed with  exit  status 1
----------------------------------------
Cleaning up...
Command  /usr/bin/python  -c  "import setuptools, tokenize;__file__='/tmp/pip_build_root/psutil/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))"  install  --record  /tmp/pip-t0gEEe-record/install-record .txt --single-version-externally-managed --compile failed with error code 1  in  /tmp/pip_build_root/psutil
Storing debug log  for  failure  in  /home/richard/ .pip /pip .log
 
 
sudo  apt-get  install  python-dev 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
   libexpat1-dev libpython-dev libpython2.7-dev python2.7-dev
The following NEW packages will be installed:
   libexpat1-dev libpython-dev libpython2.7-dev python-dev python2.7-dev
0 upgraded, 5 newly installed, 0 to remove and 17 not upgraded.
Need to get 22.4 MB of archives.
After this operation, 35.1 MB of additional disk space will be used.
Do you want to  continue ? [Y /n ] Y
Get:1 http: //cn .archive.ubuntu.com /ubuntu/  trusty /main  libexpat1-dev amd64 2.1.0-4ubuntu1 [115 kB]
Get:2 http: //cn .archive.ubuntu.com /ubuntu/  trusty /main  libpython2.7-dev amd64 2.7.6-8 [22.0 MB]
Get:3 http: //cn .archive.ubuntu.com /ubuntu/  trusty /main  libpython-dev amd64 2.7.5-5ubuntu3 [7,078 B]
Get:4 http: //cn .archive.ubuntu.com /ubuntu/  trusty /main  python2.7-dev amd64 2.7.6-8 [269 kB]
Get:5 http: //cn .archive.ubuntu.com /ubuntu/  trusty /main  python-dev amd64 2.7.5-5ubuntu3 [1,166 B]
Fetched 22.4 MB  in  42s (527 kB /s )                                              
Selecting previously unselected package libexpat1-dev:amd64.
(Reading database ... 372107 files and directories currently installed.)
Preparing to unpack ... /libexpat1-dev_2 .1.0-4ubuntu1_amd64.deb ...
Unpacking libexpat1-dev:amd64 (2.1.0-4ubuntu1) ...
Selecting previously unselected package libpython2.7-dev:amd64.
Preparing to unpack ... /libpython2 .7-dev_2.7.6-8_amd64.deb ...
Unpacking libpython2.7-dev:amd64 (2.7.6-8) ...
Selecting previously unselected package libpython-dev:amd64.
Preparing to unpack ... /libpython-dev_2 .7.5-5ubuntu3_amd64.deb ...
Unpacking libpython-dev:amd64 (2.7.5-5ubuntu3) ...
Selecting previously unselected package python2.7-dev.
Preparing to unpack ... /python2 .7-dev_2.7.6-8_amd64.deb ...
Unpacking python2.7-dev (2.7.6-8) ...
Selecting previously unselected package python-dev.
Preparing to unpack ... /python-dev_2 .7.5-5ubuntu3_amd64.deb ...
Unpacking python-dev (2.7.5-5ubuntu3) ...
Processing triggers  for  doc-base (0.10.5) ...
Processing 1 added doc-base  file ...
Processing triggers  for  man -db (2.6.7.1-1ubuntu1) ...
Setting up libexpat1-dev:amd64 (2.1.0-4ubuntu1) ...
Setting up libpython2.7-dev:amd64 (2.7.6-8) ...
Setting up libpython-dev:amd64 (2.7.5-5ubuntu3) ...
Setting up python2.7-dev (2.7.6-8) ...
Setting up python-dev (2.7.5-5ubuntu3) ...
richard@richard-Dell-System:~$  sudo  pip  install  psutil
Downloading /unpacking  psutil
   Downloading psutil-2.2.1. tar .gz (223kB): 223kB downloaded
   Running setup.py (path: /tmp/pip_build_root/psutil/setup .py) egg_info  for  package psutil
     
     warning: no previously-included files matching  '*'  found under directory  'docs/_build'
Installing collected packages: psutil
   Running setup.py  install  for  psutil
     building  '_psutil_linux'  extension
     x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSUTIL_VERSION=221 -I /usr/include/python2 .7 -c psutil /_psutil_linux .c -o build /temp .linux-x86_64-2.7 /psutil/_psutil_linux .o
     x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror= format -security build /temp .linux-x86_64-2.7 /psutil/_psutil_linux .o -o build /lib .linux-x86_64-2.7 /_psutil_linux .so
     building  '_psutil_posix'  extension
     x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I /usr/include/python2 .7 -c psutil /_psutil_posix .c -o build /temp .linux-x86_64-2.7 /psutil/_psutil_posix .o
     x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror= format -security build /temp .linux-x86_64-2.7 /psutil/_psutil_posix .o -o build /lib .linux-x86_64-2.7 /_psutil_posix .so
     
     warning: no previously-included files matching  '*'  found under directory  'docs/_build'
Successfully installed psutil
Cleaning up...
sudo  pip  install  psutil