Error when installing Python module on Ubuntu

When installing the psutil module of Python, an error of "error: command'x86_64-linux-gnu-gcc' failed with exit status 1" is reported, and the system prompts that the header file of Python is missing, that is, the system does not install the python development package. Just install it.

$ 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 forpackage 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 1in/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 get22.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 forpackage 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

Recommended Posts

Error when installing Python module on Ubuntu
Detailed tutorial on installing python3.7 for ubuntu18
Install Python3 on Ubuntu 14.04
Install Python3 on Ubuntu 16.04
Install Python3.7 on Ubuntu
Install Python 3.7 on Ubuntu 18.04 LTS
The pits encountered when installing yii2 advanced on Ubuntu
How to install Python 3.8 on Ubuntu 18.04
Install Python virtual environment on Ubuntu 18.04
Install TensorFlow (python2.7 version) on Ubuntu
Python3 module
Install the latest Python 3.6 version on Ubuntu
Method of installing django module in python
Detailed tutorial for installing CUDA9.0 on Ubuntu 16.04
How to install Python2 on Ubuntu20.04 ubuntu/focal64
Detailed tutorial for installing phpMyAdmin on Ubuntu 18.04
Deploy python3 and nginx projects on ubuntu18.04
Use python3 to install third on ubuntu
How to upgrade all Python libraries on Ubuntu 18.04
Ubuntu16 upgrade Python3
ubuntu18.04 install python2
Relearn ubuntu --python3
Solve the problem of installing VMwareTools on Ubuntu 18.04
ubuntu12.04 install python3
How to use Nginx&#39;s map module on Ubuntu 16.04
How to play happily with Python3 on Ubuntu
lamp on ubuntu
[Practice] How to install python3.6 on Ubuntu system
The latest method of installing Mongodb on Ubuntu 16.04
ubuntu18.04 install python
How to add logging module to Nginx on Ubuntu 16.04
ubuntu installation error
Solve the problem of installing Theano on Ubuntu19
Python Lesson 37-Module
ubuntu16.04 upgrade python2
How to add the gzip module to Nginx on Ubuntu 14.04
Solutions to the black screen when installing ubuntu (3 types)
Ubuntu18.04 switch Python version
install vscode on ubuntu18
Install Redis on Ubuntu
Python3 built-in module usage
Install R4 on ubuntu20
Install nvtop on Ubuntu 18.04
Install postgresql-10 on Ubuntu 18.04
Install python3.6 under Ubuntu 16.04
ubuntu configuration python, Red
Install docker on Ubuntu
Ubuntu16.04 switch python version
Python MySQLd under Ubuntu
Install Docker on ubuntu18.04
Install nodejs10 on Ubuntu16
[python] python2 and python3 under ubuntu
Install mysql on Ubuntu 14.04
Install Django on ubuntu
Install Pytorch+CUDA on Ubuntu 16.04
Python virtual environment: Ubuntu16.04
Python3 external module use
Install rJava on Ubuntu18
Install JDK10+ on Ubuntu
Install python in Ubuntu
Prettytable module of python