树莓派安装psutil失败报错
安装pip3 install psutil
root@ubuntu:/home/ubuntu# pip3 install psutil
报错信息
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xffffb4d05b80>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /simple/psutil/
Collecting psutil
...
...
running build_ext
building 'psutil._psutil_linux' extension
creating build/temp.linux-aarch64-cpython-38
creating build/temp.linux-aarch64-cpython-38/psutil
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=594 -DPy_LIMITED_API=0x03060000 -DPSUTIL_LINUX=1 -I/usr/include/python3.8 -c psutil/_psutil_common.c -o build/temp.linux-aarch64-cpython-38/psutil/_psutil_common.o
psutil/_psutil_common.c:9:10: fatal error: Python.h: No such file or directory
9 | #include <Python.h>
| ^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/aarch64-linux-gnu-gcc' failed with exit code 1
----------------------------------------
ERROR: Failed building wheel for psutil
Failed to build psutil
ERROR: Could not build wheels for psutil which use PEP 517 and cannot be installed directly
解决方案
修改DNS:
$ sudo vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
保存后再次执行sudo apt-get update命令
安装必要的依赖,执行这个命令:
sudo apt-get install python3-dev python3-pip libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev
执行安装指令:
pip3 install psutil